Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery Form validation for Housenumber

Tags:

jquery

regex

How to validate the below Housenumber using jquery Form validation?

1
1b
12
12b
123
123b
1234
1234b

the letter should be always last position , but not required. Please help me to create regular expression.

like image 619
Sanjeev Chauhan Avatar asked Dec 17 '22 08:12

Sanjeev Chauhan


2 Answers

The following RegExp will do:

/^\d+[a-zA-Z]*$/
  • ^ Must start with
  • \d+ Any number (\d), at least once (+)
  • [a-zA-Z]* Some letters [a-zA-Z] (optional: *)
  • $ Must end here
like image 151
Rob W Avatar answered Jan 05 '23 02:01

Rob W


regex "^\\d+/?\\d*[a-zA-Z]?(?<!/)$" will match numbers like:

  • 67
  • 67/33
  • 67/33a
  • 67a
  • 67/a
like image 45
Alyona Avatar answered Jan 05 '23 01:01

Alyona