File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Regular Expressions/Indian Mobile Numbers Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ var regex = / ^ (?: (?: \+ | 0 { 0 , 2 } ) 9 1 ( \s * [ \ - ] \s * ) ? | [ 0 ] ? ) ? [ 7 8 9 ] \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
+ }
Original file line number Diff line number Diff line change
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 />
You can’t perform that action at this time.
0 commit comments