user1639485
user1639485

Reputation: 808

Regular expression validation in Javascript

I am looking to validate an input text against the following pattern in JS/JQuery: <some_string>:<some_string>.

Examples:

I know this might be too naive, but appreciate any help here.

Upvotes: 0

Views: 62

Answers (2)

Pablo Matias Gomez
Pablo Matias Gomez

Reputation: 6813

You could use this:

^[A-Z0-9]+:[A-Z0-9]+$

That will match your examples and any other that has at least 1 character in each side and only has upper case letters and numbers.

You can refer to this answer in order to know how to test a regex against a string.

Upvotes: 1

0xdw
0xdw

Reputation: 3842

Try this

"A110:B120 AB12C:B123".match(/(\w+:\w+)/);

MATCH 
1.  `A110:B120`
2.  `AB12C:B123`

or

"A110:B120".match(/(\w+)+:+(\w+)/);

MATCH 
1.  A110
2.  B120

Upvotes: 0

Related Questions