Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Regular expression

Neha Tiwari5
Tera Contributor

Hi,

 

I need a regular expression for

"Phone number needs to meet following criteria"
"1. Starts with '+'
"2. Followed by digit 1 - 9
"3. Followed by digits 0 - 9 with / without space in between.
4. Should not have any alphabets in it.";

 

via OnChange client script

1 REPLY 1

Mark Manders
Giga Patron
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var phonePattern = /^\+[1-9][0-9\s]*$/;

    if (!phonePattern.test(newValue)) {
        g_form.showFieldMsg(control.name, 'Phone number must start with + followed by a digit (1-9), and can include digits (0-9) with optional spaces.', 'error');
        g_form.clearValue(control.name);  // Optionally clear the invalid value
    } else {
        g_form.hideFieldMsg(control.name);
    }
}

Not sure why asking once wasn't enough, but here again the solution.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark