Skip to content

Commit 0b558c5

Browse files
Create Validate PhNo.js
1 parent 05b9e6a commit 0b558c5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
if (isLoading || !newValue) return;
3+
4+
var fieldName = control.name;
5+
6+
// Split the string
7+
var area = newValue.substring(1, 4);
8+
var firstThree = newValue.substring(6, 9);
9+
var lastFour = newValue.substring(10, 14);
10+
11+
if (
12+
newValue[0] !== '(' || newValue[4] !== ')' || newValue[5] !== ' ' || newValue[9] !== '-' ||
13+
isNaN(parseInt(area)) || isNaN(parseInt(firstThree)) || isNaN(parseInt(lastFour))
14+
) {
15+
g_form.showFieldMsg(
16+
fieldName,
17+
'Phone Number must be in the format (123) 456-7890',
18+
'error',
19+
false
20+
);
21+
g_form.setValue(fieldName, '');
22+
}
23+
}

0 commit comments

Comments
 (0)