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

VISHAL69
Tera Contributor

willem if i m trying to run this code than it is still excepting 11 digits , not 10 digits.

I am trying to apply this validation on my catalog item variable.

I hope that doesn't make any difference?

 

Plz check if i am doing any mistake?

find_real_file.pngfind_real_file.png

Use below regex

 

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

 

Regards,

Sachin

Let me know if this works for you 🙂

Sudhanshu Talw1
Tera Guru

Use the following regex:

function onSubmit(){

var mobileno=g_form.getValue("field name");//enter appropriate field name

var regex="^0\d{10}";

if(!regex.test(mobileno){

g_form.addInfoMessage("Please enter a valid no");

g_form.clearValue("field name");//enter appropriate field name

g_form.getControl("field name").focus();//enter appropriate field name

return false;

}

}

find_real_file.png

I already gave that exact same regex.