0

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

Examples:

  • A110:B120
  • AB12C:B123

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

Jordan Running
  • 102,619
  • 17
  • 182
  • 182
user1639485
  • 808
  • 3
  • 14
  • 26
  • 2
    please add some examples and the wanted result ... – Nina Scholz May 11 '16 at 15:54
  • Based on what you say, you can only validate `:` and not `:`, which is `^[^:]+:[^:]+$`. Anything more specific and you will _miss_ matches you should get. –  May 11 '16 at 16:40

2 Answers2

1

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.

Community
  • 1
  • 1
Pablo Matias Gomez
  • 6,614
  • 7
  • 38
  • 72
0

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
0xdw
  • 3,755
  • 2
  • 25
  • 40