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

sriram35
Kilo Guru

Hi Vishal,

 

can you try the below code for number validation?

onChange Client Script:

var regexp = /^\d{11}$/;
if(!regexp.test(newValue))
{
g_form.setValue('phone_number','');
g_form.showFieldMsg('phone_number','Please enter a eleven-digit valid mobile number',"error");
}

 

Hope this helps!

If you have any more questions, please let me know.

If I have answered your question, please mark my response as correct and helpful.

Thanks,

Sriram

 

@VISHAL This does not enforce the "must start with 0".

 

Yes William is correct this will allow the number to be start with any digit & with this invalid numbers get added to your table. Thanks Sudhanshu

Hi,

As said by Willem, it will not add 0 every time at the beginning also it will not stop submitting the form.

You have to use other provided regEx in onSubmit client script.

Request you to mark correct response as correct so that this will be helpful for others who is looking for similar in future.

Thanks,

Dhananjay.