Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression - allow digits but no dash punctuation mark

Tags:

regex

I want to write a regular expression. Here is my basic requirement:

  1. Only allow 11 numbers.
  2. Cannot have a dash (-) inside these 11 numbers.

Here is the regular expression that I wrote:

\d{11}[^-]

Examples:
a) 12345654321 => Valid
b) 123-4567890 => Invalid
c) -1234567890 => Invalid
d) 1234567890- => Invalid

I didn't get the proper result. How should I correct it?

like image 678
Michael Kuan Avatar asked Nov 18 '25 03:11

Michael Kuan


1 Answers

^\d{11}$ 

this should do it....... With anchors

like image 162
vks Avatar answered Nov 20 '25 20:11

vks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!