I am using javascript regex to test a string. It should fail the text string but somehow its passing it. Any clue, what is wrong with this code?
<script>
var format = "^[a-zA-Z\.\-' ]*[a-zA-Z]+[a-zA-Z\.\-' ]*";
var testingValue = "FN306716";
var regex = new RegExp(format);
if (regex.test(testingValue) == false) {
alert('validation failed');
}
else {
alert('validation passed');
}
</script>
.to'(.-') is not valid, which results in an error.-could be put at the end, but to me it's more readable if it's escaped (no matter where it is). As for the.- I can't see a reason why you'd need to escape it, but I think jslint complains if you don't (just saying)