Reputation: 611
I have to validate if the word contains first letter as "A" second as "R" third as "T". I want to validate it as user is typing so want to validate it character by character. Is there a way in regex?
Upvotes: 2
Views: 52
Reputation: 2029
You can try this regex !
^(A|AR|ART.*)$
^ represents that the starting character should be like 'A' or 'AR' or 'ART' .The pipe '|' shows that the conditional that multiple regex are possible and '$' signs indicate the end of the line .
I test it through regex 101 & attached is the output !
Upvotes: 1
Reputation: 740
Something like this should work: ^(A|AR|ART|ART.+)$
. Only "A", "AR", "ART", and "ART..." are valid. Though, there's probably a shorter/better way to do it.
Upvotes: 1