0

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...

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.