- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 07:16 AM
Hi All,
we will restrict phone regex
We will allow digits with dashes in between, but the dashes could be optional.
Example: 555555555 or 555-555-555 (no leading zero)
Currently we have the following regex:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var regex = /^[1-9][0-9]{0,29}$/; // regex for phone numbers
How can we solve this? Could you please help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 03:52 AM
Hi @BuriB,
I've tweaked it slightly and tested it to ensure it works as required:
(Please note, the 4 highlighted in bold in the ending brackets it the number used to determine the minimum and maximum number. So in using the regex as shown below you can have 9 minimum (3+3+3) and 10 maximum (3+3+4). If you want to extending this to 11 numbers for example, change the 4 to a 5.)
/^[1-9]{3}(-)?\d{3}(-)?\d{3,4}$/gm;
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 05:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 08:11 AM - edited 09-19-2024 08:16 AM
Hi @BuriB,
(Updated since original post @BuriB )
The regex required to match either '123123123' or '123-123-123' with no leading zero and no spaces is:
/^\d{3}(-)?\d{3}(-)?\d{3}$
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 11:56 PM
hi Robbie,
its not working as expected. It allows leading zero and is restricted to 9 digits in total but the number could more than 9 digits
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 02:33 AM - edited 09-20-2024 02:38 AM
Hi @BuriB
Please try with below regex :
/^[1-9 \-]+$/gm
Output :
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 03:52 AM
Hi @BuriB,
I've tweaked it slightly and tested it to ensure it works as required:
(Please note, the 4 highlighted in bold in the ending brackets it the number used to determine the minimum and maximum number. So in using the regex as shown below you can have 9 minimum (3+3+3) and 10 maximum (3+3+4). If you want to extending this to 11 numbers for example, change the 4 to a 5.)
/^[1-9]{3}(-)?\d{3}(-)?\d{3,4}$/gm;
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie