
Untitled
By: a guest on
Jul 1st, 2012 | syntax:
None | size: 0.86 KB | hits: 15 | expires: Never
YA Javascript Regex Question
A-z 0-9 - _ ' & .
/^[A-z0-9_]+(-)+$/i
/^[a-zA-Z0-9&_.-']+$/
<script type="text/javascript">
//A-z 0-9 - _ ' & .
//valid
var test_string = "This'Is'-Val1d&_.";
if (test_string.match(/^[a-zA-Z0-9&_.-']+$/)){
alert("first test matched");
}else{
alert("first test did not match");
}
//invalid - whitespace not allowed
test_string = "This IsNot- Va'l1d & _ .";
if (test_string.match(/^[a-zA-Z0-9&_.-']+$/)){
alert("second test matched");
}else{
alert("second test did not match");
}
//invalid - ! is not allowed
test_string = "'ThisIsNotValid!'";
if (test_string.match(/^[a-zA-Z0-9&_.-']+$/)){
alert("third test matched");
}else{
alert("third test did not match");
}
</script>
var regex = /^[a-z0-9_-.'&]/i;
/^[-w.'&]+$/