Sanjeev Chauhan
Sanjeev Chauhan

Reputation: 4097

jquery Form validation for Housenumber

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.

Upvotes: 4

Views: 5237

Answers (3)

Alyona
Alyona

Reputation: 1792

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

  • 67
  • 67/33
  • 67/33a
  • 67a
  • 67/a

Upvotes: 2

Saurabh
Saurabh

Reputation: 7964

Please correct me if wrong. String can can not end with two more digits. In this case "\d+[a-zA-Z]?" should work

Upvotes: 1

Rob W
Rob W

Reputation: 349262

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

Upvotes: 9

Related Questions