0

I want to validate my string input with regx in typescript/javascript.

string input is 9 digit followed by WA

I tried using below two Regx, its able to validate digit part, but couldn't validate end of string to be WA.

val.matches('^[0-9]') && val.matches("WA$") 
val.matches('^[0-9]WA$') 
Krunal Parmar
  • 491
  • 2
  • 19

1 Answers1

4

You could use a regex approach with test():

var input = "text 123456789wa";
if (/\d{9}WA$/i.test(input)) {
    console.log("MATCH");
}
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360