Leandro Castro
Leandro Castro

Reputation: 558

Regex to find numbers and letters

I would find validate the following syntax using regex from zero to 99, then "x", then again 0 to 99.

Example:

03x10
01x08 
99x99

Upvotes: 0

Views: 79

Answers (3)

walid toumi
walid toumi

Reputation: 2282

Try this:

From 0 to 99

^[0-9][1-9]?x[0-9][1-9]?$

To allow from 00 to 99:

 ^[0-9][0-9]?x[0-9][0-9]?$

Upvotes: 1

Avinash Raj
Avinash Raj

Reputation: 174844

Don't forget to include start ^ and end $ anchors in your regex.

^\d{2}x\d{2}$
  • \d{2} will match exactly two digits.

DEMO

Upvotes: 3

BadZen
BadZen

Reputation: 4274

 /[0-9]{2}x[0-9]{2}/

should do the trick...

Upvotes: 0

Related Questions