Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
We are building a form in ServiceNow where a user must enter their phone number.
The requirement is that only valid Indian mobile numbers should be accepted. A valid number should:

Optionally start with 0 or 91

Be exactly 10 digits long

Start with digits 6, 7, 8, or 9

If the user enters anything invalid, the form should not be submitted, and an error message should be shown.

g_form.getValue → gets the phone field value.
Regex → allows numbers like 9876543210, 0919876543210, 919876543210.
Validation → If the value is invalid, shows alert and blocks submission.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function onSubmit() {

var phone=g_form.getValue('phone_number_field');//09898989
var pregex=/(0|91)?[6-9][0-9]{9}/;
if(!pregex.test(phone)){
alert("Enter correct phone number");
return false;
}
Loading