Required a regular expression for phone number which has 10 digits mandatory and no constantly repeating numbers i.e. 11111111111 etc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2022 04:57 AM
Required a regular expression for phone number which has 10 digits mandatory and no constantly repeating numbers i.e. 11111111111 etc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2022 05:50 AM
var number = g_form.getValue('field_name');
var check = /^[0-9]{10}/;
var result = number.match(check);
if(result==true)
{ g_form.setValue('field_name', 'number'); }
else
{ alert("Dear Requestor, please make sure that the number you provide is 10 digits long"); }
please mark helpful /correct based on impact
Regards,
Aniket S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2022 07:13 AM
Hi Vinay,
Please find the snippet below, wrote the code in view of US mobile phone number validation
var phoneNum = "+14445551234"
phoneNum = phoneNum.replace(/ /g, ""); //Remove all spaces from phone number
var validUSPhoneExp = /^((\+1 ?)?((\(\d{3}\))|(\d{3}) ?\-) ?(\d{3}) *\- *\d{4})|((\+1 ?)?)\d{10}$/;
var phoneNumWithoutDelimeters = phoneNum.replace(/( |\(|\)|\-)/g,"");
var invalidPattern1 = /^(\+1)?(1{10}|2{10}|3{10}|4{10}|5{10}|6{10}|7{10}|8{10}|9{10}|0{10})$/; //Phone number with same digits
var invalidPattern2 = /^(\+1)?(\d{3}(555)\d{4})$/; // US mobile numbers used in movies or TV have 555 in the 4th 5th and 6th digits of the phone numbers. Treating these as invalid.
var result = validUSPhoneExp.test(phoneNum) && !invalidPattern1.test(phoneNumWithoutDelimeters) && !invalidPattern2.test(phoneNumWithoutDelimeters);
var finalNum = "";
if(result == true) {
// phoneNum varible has correct phone number available.
}
Above code validates for below formats returns true in the result with some exceptions noted below these formats.
(xxx)xxx-xxx
+1(xxx)xxx-xxx
(xxx) xxx-xxx
(xxx) xxx -xxx
xxx-xxx-xxx
xxx - xxx - xxx
xxx -xxx -xxx
+1xxx -xxx -xxx
+1xxxxxxxxxx
But if the mobile numbers have 555 in the 6,7,8 digits, they are used in movies in US and they are not allocated to anyone. Above code treats them as invalid phone numbers.
If the US mobile phone or 10 digit mobile number has same number in all the places they are treated as invalid numbers.
For example, all the numbers below are treated as invalid.
+11111111111
+1(111)111-1111
+1111-111-1111
+1 111-111-1111
+11115551234
+1111-555-1234
Thanks and regards,
Subrahmanyam Satti