Click here to Skip to main content
15,125,299 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: data import via API Pin
Afzaal Ahmad Zeeshan24-Sep-21 5:11
mveAfzaal Ahmad Zeeshan24-Sep-21 5:11 
GeneralRe: data import via API Pin
Francesco Reboldi24-Sep-21 6:13
MemberFrancesco Reboldi24-Sep-21 6:13 
GeneralRe: data import via API Pin
Francesco Reboldi25-Sep-21 7:26
MemberFrancesco Reboldi25-Sep-21 7:26 
QuestionRegex not keeping the . or decimal with currency value with keydown event. Pin
jkirkerx23-Sep-21 10:06
professionaljkirkerx23-Sep-21 10:06 
AnswerRe: Regex not keeping the . or decimal with currency value with keydown event. Pin
Member 1532961323-Sep-21 10:32
MemberMember 1532961323-Sep-21 10:32 
GeneralRe: Regex not keeping the . or decimal with currency value with keydown event. Pin
jkirkerx23-Sep-21 10:39
professionaljkirkerx23-Sep-21 10:39 
GeneralRe: Regex not keeping the . or decimal with currency value with keydown event. Pin
Member 1532961324-Sep-21 2:07
MemberMember 1532961324-Sep-21 2:07 
AnswerRe: Regex not keeping the . or decimal with currency value with keydown event. Pin
jkirkerx29-Sep-21 13:19
professionaljkirkerx29-Sep-21 13:19 
I'm back to working on this today. This works in Chrome, but not in firefox. I lose the decimal in firefox.
So in Chrome, I can type 1.23, but in Firefox it types 123

This is a filter or sort of a mask for input element of a number step .01

I thought it was the regex, and monkeyed around for about an hour with it. But it seems to have something to do with the keydown event in Firefox.

I tried this pattern
const pattern = "/^[0-9]+\\.[0-9]{2}/g";
Tried this function style
function formatCurrency(value) {

    // if input value is falsy eg if the user deletes the input, then just return
    if (!value) return value;

    // clean the input for any non-digit values.
    const pattern = "/^[0-9]+\.[0-9]{2}/g";
    return value.replace(pattern, "");

}

And now I'm here. It's just the dot or decimal in FireFox. Maybe it is my regex.
I thought maybe it was the textbox, so I did a console output, same thing.
Oh, I know this function looks weird, like why would I replace what I want to keep. I have no answer for that.
I am stumped... Calling it quits for today. Maybe it's a PHP issue?
document.addEventListener("keydown", (e) => {
    const el = e.target;
    if (el.classList.contains("currency")) {
        // console.debug(el.id, el.value);
        el.value = formatCurrency(el.value);
    }
});

function formatCurrency(value) {

    // if input value is false, eg if the user deletes the input, then just return
    if (!value) return value;

    // clean the input for any non-digit values except .
    const pattern = '^(\d+(.\d{0,2})?|.?\d{1,2})$';
    console.log('value replace=', value.replace(new RegExp(pattern)));
    return value.replace(new RegExp(pattern));

}
If it ain't broke don't fix it
Discover my world at jkirkerx.com

GeneralRe: Regex not keeping the . or decimal with currency value with keydown event. [Perhaps Solved] Pin
jkirkerx29-Sep-21 14:18
professionaljkirkerx29-Sep-21 14:18 
QuestionHow does the compare function work with numerical sort? Pin
Ryan Blake 202126-Aug-21 16:51
MemberRyan Blake 202126-Aug-21 16:51 
AnswerRe: How does the compare function work with numerical sort? Pin
Peter_in_278026-Aug-21 19:22
professionalPeter_in_278026-Aug-21 19:22 
GeneralRe: How does the compare function work with numerical sort? Pin
Ryan Blake 202128-Aug-21 14:45
MemberRyan Blake 202128-Aug-21 14:45 
QuestionBrowser Side Recovery Pin
milo-xml3-Aug-21 10:06
professionalmilo-xml3-Aug-21 10:06 
AnswerRe: Browser Side Recovery Pin
Richard Deeming4-Aug-21 0:48
mveRichard Deeming4-Aug-21 0:48 
GeneralRe: Browser Side Recovery Pin
milo-xml4-Aug-21 4:20
professionalmilo-xml4-Aug-21 4:20 
Questioni have been learning javascript for a long time now but still dont know what to build Pin
samuel unachukwu23-Jul-21 23:47
Membersamuel unachukwu23-Jul-21 23:47 
AnswerRe: i have been learning javascript for a long time now but still dont know what to build Pin
SeeSharp226-Jul-21 9:51
MemberSeeSharp226-Jul-21 9:51 
AnswerRe: i have been learning javascript for a long time now but still dont know what to build Pin
Bohdan Stupak30-Jul-21 5:10
professionalBohdan Stupak30-Jul-21 5:10 
AnswerRe: i have been learning javascript for a long time now but still dont know what to build Pin
Mate Peric5-Aug-21 15:35
MemberMate Peric5-Aug-21 15:35 
Questionwhat to study after javascript? Pin
E-FANIE Rh19-Jul-21 10:16
MemberE-FANIE Rh19-Jul-21 10:16 
AnswerRe: what to study after javascript? Pin
SeeSharp219-Jul-21 10:44
MemberSeeSharp219-Jul-21 10:44 
GeneralRe: what to study after javascript? Pin
Miguel Santico21-Jul-21 18:50
professionalMiguel Santico21-Jul-21 18:50 
AnswerRe: what to study after javascript? Pin
Bohdan Stupak30-Jul-21 5:04
professionalBohdan Stupak30-Jul-21 5:04 
QuestionHow can I minimize the entire browser? Pin
Member 1528061310-Jul-21 22:32
MemberMember 1528061310-Jul-21 22:32 
AnswerRe: How can I minimize the entire browser? Pin
Richard Deeming11-Jul-21 23:10
mveRichard Deeming11-Jul-21 23:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.