MOBILE NUMBER VALIDATION

VISHAL69
Tera Contributor
  • Create any sample table and create sample field mobile no and when user try to submit record following condition should met :

  1. Mobile no should be 11 digit no and must start with 0 always, and should be a valid Indian number. Then submission should work

  2. If conditions fails record should not be submitted.

I want to run client script for this , can anyone help me out?   I want the code which i should run to fulfill my req.

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

Use Variable Validation Regex like so:

find_real_file.png

 

The regular expression:

^[0]\d{10}

 

You can add the validation to a variable like this:

find_real_file.png

 

Or if not in the catalog, you can use an onChange CLient script on the 'phone_number' field:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var reg = /^[0]\d{10}/;
    if (!reg.test(newValue)) {
        g_form.setValue('phone_number', '');
        g_form.showFieldMsg('phone_number', 'Phone number should start with 0 and be 11 digits', "error");
    }
}

View solution in original post

18 REPLIES 18

sachin_namjoshi
Kilo Patron
Kilo Patron

You should use variable regex if this is catalog item for mobile number validation.

 

find_real_file.png

 

Regards,

Sachin

Willem
Giga Sage
Giga Sage

Use Variable Validation Regex like so:

find_real_file.png

 

The regular expression:

^[0]\d{10}

 

You can add the validation to a variable like this:

find_real_file.png

 

Or if not in the catalog, you can use an onChange CLient script on the 'phone_number' field:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var reg = /^[0]\d{10}/;
    if (!reg.test(newValue)) {
        g_form.setValue('phone_number', '');
        g_form.showFieldMsg('phone_number', 'Phone number should start with 0 and be 11 digits', "error");
    }
}

VISHAL69
Tera Contributor

Hi thanks for the reply to my question.

But what if my req is that it should take only 10 digits and should start with 9.

 

Than what changes needs to be done in the code given from your side?

Use below regex for mobile number validation as per your format.

 

^([0|\+[0-9]{1,5})?([7-9][0-9]{9})$


Regards,
Sachin

^[9]\d{9}