- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 09:55 AM
-
Create any sample table and create sample field mobile no and when user try to submit record following condition should met :
-
Mobile no should be 11 digit no and must start with 0 always, and should be a valid Indian number. Then submission should work
-
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 10:53 AM
Use Variable Validation Regex like so:
The regular expression:
^[0]\d{10}
You can add the validation to a variable like this:
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");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 11:14 AM
Onsubmit is a good idea. However, might still be good to have the field message as well. And instead of info message, use error message. Like so:
function onSubmit() {
var phoneNr = g_form.getValue('phone_number')
var reg = /^[0]\d{10}/;
if (!reg.test(phoneNr)) {
g_form.setValue('phone_number', '');
g_form.addErrorMessage("Phone number is invallid");
g_form.showFieldMsg('phone_number', 'Phone number should start with 0 and be 11 digits', "error");
return false
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 11:19 AM
Hey Vishal,
refer below code ,write onChange client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var pattern = /^[(]?(\d{3})[)]?[-|\s]?(\d{3})[-|\s]?(\d{4})$/;
if(!pattern.test(newValue)){
alert('Phone enter a valid phone number');
g_form.setValue('variable_name', '');
}
}
also you can refer below links for more,
kindly mark Correct and Helpful if applicable.
Regards,
Indrajit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2022 07:53 PM
how do i restrict that phone number must not be enter more than 10 numbers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2024 11:01 PM
onSubmit script error: TypeError: pattern.exec is not a function: function () { [native code]) how to resolve this issue in regex validate phone number Can anyone tell this error