cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Unkn0wn
Helper I
Helper I

number validation

Hello,

I'm trying to play with ismatch to validate number, my requirement is to have a 10digits which might includes dot(.) or hyphen(-) and I was able to achieve regex for some extent using "\(?[0-9]{3}\)?[.-]? *[0-9]{3}[.-]? *[.-]?[0-9]{4}" which helps me validating 123-456-7890 and 1234567890 and 123.456.7890 but it also showing valid for 123-456.789 and 123.456-789 which are invalid. is there a way to check or restrict the user whatever the character was entered for the first checked with next special character ? 

2 ACCEPTED SOLUTIONS

Accepted Solutions
indhaa
Impactful Individual
Impactful Individual

Use my formulae . I pasted that after testing

IsMatch(txtinput.Text,"\d{1,9}") || IsMatch(txtinput.Text,"\d{1,3}\-\d{1,3}\-\d{1,4}") || 
IsMatch(txtinput.Text,"\d{1,3}\.\d{1,3}\.\d{1,4}")

View solution in original post

StalinPonnusamy
Community Champion
Community Champion

Hi @Unkn0wn 

 

We can check space like

IsMatch(txtinput.Text,"\(?[0-9]{3}\)?[.-]? *[0-9]{3}[.-]? *[.-]?[0-9]{4}") && !("-" in txtinput.Text && "." in txtinput.Text) && !(" " in txtinput.Text)

but still, need to find the condition for 123-4567890

View solution in original post

8 REPLIES 8
indhaa
Impactful Individual
Impactful Individual

Can you show your code. 

You can enter each scenario separately with an && so that its validate like that

Unkn0wn
Helper I
Helper I

Hi @indhaa the code is same isMatch(txtinput.text, "\(?[0-9]{3}\)?[.-]? *[0-9]{3}[.-]? *[.-]?[0-9]{4}")

 

Valid conditions

1234567890 

123-456-7890

123.456.7890

 

Invalid conditions

123-456.7890

123.456-7890

 

@StalinPonnusamy @RandyHayes @WarrenBelz @zmansuri  any help here

 

indhaa
Impactful Individual
Impactful Individual

Can you try like this . Just amend && to || depending on what you are trying to do

 

IsMatch(txtinput.Text,"\d{1,9}") && IsMatch(txtinput.Text,"\d{1,3}\-\d{1,3}\-\d{1,4}") && 
IsMatch(txtinput.Text,"\d{1,3}\.\d{1,3}\.\d{1,4}")
IsMatch(txtinput.Text,"\d{1,9}") || IsMatch(txtinput.Text,"\d{1,3}\-\d{1,3}\-\d{1,4}") || 
IsMatch(txtinput.Text,"\d{1,3}\.\d{1,3}\.\d{1,4}")

 

StalinPonnusamy
Community Champion
Community Champion

Hi @Unkn0wn 

Please try this 

IsMatch(txtinput.Text,"\(?[0-9]{3}\)?[.-]? *[0-9]{3}[.-]? *[.-]?[0-9]{4}") && !("-" in txtinput.Text && "." in txtinput.Text)

 

StalinPonnusamy_0-1631765745449.png

 

 

 

Unkn0wn
Helper I
Helper I

@StalinPonnusamy  perfect. but it is showing true for 123 456.7890 and 123.456 7890, 123-4567890 which should ideally be false

indhaa
Impactful Individual
Impactful Individual

Use my formulae . I pasted that after testing

IsMatch(txtinput.Text,"\d{1,9}") || IsMatch(txtinput.Text,"\d{1,3}\-\d{1,3}\-\d{1,4}") || 
IsMatch(txtinput.Text,"\d{1,3}\.\d{1,3}\.\d{1,4}")

View solution in original post

StalinPonnusamy
Community Champion
Community Champion

Hi @Unkn0wn 

 

We can check space like

IsMatch(txtinput.Text,"\(?[0-9]{3}\)?[.-]? *[0-9]{3}[.-]? *[.-]?[0-9]{4}") && !("-" in txtinput.Text && "." in txtinput.Text) && !(" " in txtinput.Text)

but still, need to find the condition for 123-4567890

View solution in original post

StalinPonnusamy
Community Champion
Community Champion

Hi @Unkn0wn

 

Please let us know if anything needs on your post. We can help with this.

 

Please do not forget to give kudos if you find the suggestion helpful or Accept it as a solution if works fine to help other users to find it useful.

 

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,344)