- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 01:10 PM
Hello,
I want a REGEX for a phone number to accept only numbers and only in this format
Allows formats of (999) 999-9999, 999-999-9999 ONLY
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 08:17 AM
Hi @maryc ,
you can try these regex : - ^\(?\d{3}\)?[-\s]?\d{3}-\d{4}$ or ^\((\d{3})\)\s*(\d{3})-(\d{4})|(\d{3})-(\d{3})-(\d{4})$
If my answer solved your issue, please mark my answer as Correct ✔️ & Helpful 👍 based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 09:12 AM
Hello @maryc
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}
// Allows formats of (999) 999-9999, 999-999-9999, and 9999999999
var pattern = /^[(]?(\d{3})[)]?[-|\s]?(\d{3})[-|\s]?(\d{4})$/;
if(!pattern.test(newValue)){
alert('Phone enter a valid phone number');
g_form.setValue('u_mobile_number', '');
}
}
Use this in OnChange Client Script
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 08:17 AM
Hi @maryc ,
you can try these regex : - ^\(?\d{3}\)?[-\s]?\d{3}-\d{4}$ or ^\((\d{3})\)\s*(\d{3})-(\d{4})|(\d{3})-(\d{3})-(\d{4})$
If my answer solved your issue, please mark my answer as Correct ✔️ & Helpful 👍 based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 09:12 AM
Hello @maryc
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}
// Allows formats of (999) 999-9999, 999-999-9999, and 9999999999
var pattern = /^[(]?(\d{3})[)]?[-|\s]?(\d{3})[-|\s]?(\d{4})$/;
if(!pattern.test(newValue)){
alert('Phone enter a valid phone number');
g_form.setValue('u_mobile_number', '');
}
}
Use this in OnChange Client Script
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 10:06 PM
Hello @maryc
As per new community rules, You can mark multiple solutions.
Plz mark my solution as Accept, if you find it helpful. it will help future users to get the correct solutions.
Regards,
Samaksh