Skip to content

Commit 15c5034

Browse files
authored
Regular expression for Indian mobile numbers (ServiceNowDevProgram#849)
* Create code.js * Create readme.md
1 parent c0a706f commit 15c5034

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var regex = /^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$/;
2+
var fieldValue = '919876543210'; // Replace with your field name
3+
if (fieldValue && fieldValue.match(regex)) {
4+
gs.info('Mobile number is valid.');
5+
} else {
6+
gs.info('Invalid mobile number format.');
7+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Here's an example of how you can utilize regex in a Business Rule in ServiceNow:
2+
3+
```
4+
(function executeRule(current, previous) {
5+
var regex = /^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$/;
6+
var fieldValue = '919876543210'; // Replace with your field name
7+
if (fieldValue && !fieldValue.match(regex)) {
8+
current.setAbortAction(true);
9+
gs.info('Invalid mobile number format.');
10+
}
11+
})(current, previous);
12+
```
13+
# Valid Scenarios
14+
+91-9883443344 <br />
15+
9883443344 <br />
16+
09883443344 <br />
17+
919883443344 <br />
18+
0919883443344 <br />
19+
+919883443344 <br />
20+
+91-9883443344 <br />
21+
22+
# Invalid Scenarios
23+
24+
WAQU9876567892 <br />
25+
ABCD9876541212 <br />
26+
0226-895623124 <br />
27+
6589451235 <br />
28+
0924645236 <br />
29+
0222-895612 <br />
30+
098-8956124 <br />
31+
022-2413184 <br />

0 commit comments

Comments
 (0)