63
Views
4
Comments
Solved
Regex
Question

Hi Guys!


I'm using the following regular expression to only allow numbers and hyphens, I just put a number like: 75648-a he allowed. 

Exp:  

"^[0-9]|[-]*$"

2019-05-16 13-55-52
João Henriques
Solution

Hi Fabiano,
For the pattern that you've wrote, here's the Regular Expression:

^[0-9]+([0-9]|-[0-9])+$


You can try it with the values you added here on https://regexr.com/

2019-05-16 13-55-52
João Henriques

Hi Fabiano,


You can use this "^[0-9]+([0-9]-)+$" it will validate numbers + hyphen.
But note this is for the use case: 75648-

If you want a specific pattern, let us know.


Also this web site is really cool on helping create regexs:

https://regexr.com/

Thank you.



UserImage.jpg
Fabiano Silva

In this case, the input number pattern will be:

896644-7

8966447

24515-0

6874598235

2019-05-16 13-55-52
João Henriques
Solution

Hi Fabiano,
For the pattern that you've wrote, here's the Regular Expression:

^[0-9]+([0-9]|-[0-9])+$


You can try it with the values you added here on https://regexr.com/

UserImage.jpg
Fabiano Silva

Thank you!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.