Reputation: 3
I need to validate a regular expression aganist a string veryt strictly only what is there in string. But at present i don't see such a function for regular expression since bot exec and test doesn't check strictly. for example say i have regular expression for validating 43a^2b^2, but even its 43a it's returning true, as a part of string is present in reg exp. i need true only when exact match is found, is there any way achieve this?
The code I am using at present:
var isRegExp:Boolean = regExp.test(value1);
Thanks in advance...
Upvotes: 0
Views: 225
Reputation: 4546
Using the beginning of string ^
and end of string $
tests should work.
var regExp:RegExp = /^43a$/;
regExp.test('43a'); //true
regExp.test('43a^2b^2'); //false
You can read more about anchors here.
Upvotes: 1