Trying to set up a simple .jsp to test JavaScript regular expressions and avoid having to clean/build/republish my testing server every time I make a change. The existing code was taken from a project on which I was working to add recognition of Spanish characters, but this code as it is doesn’t seem to catch any mismatches at all.
<html>
<head>
<script language="JavaScript">
function isValidTarget(target) {
if (regexTarget.target.search(/^[a-zA-Z\#\@\!\&\.\*\-:;<>"',\?0-9 ]+$/) == -1) {
alert("Your input contains one or more invalid characters.");
}
}
</script>
</head>
<body>
<form name="regexTarget" method="post" onSubmit="return isValidTarget(this)">
Target: <input type="text" name="target"/>
<input type="submit" value="Submit" />
</form>
</body>
</html>
You’re trying to search the DOM node instead of its value. Try this: