Javascript regular expression: \W |
<input type="button" value="No Match1" onclick="javascript:demo('a');return false;" /> <input type="button" value="No Match2" onclick="javascript:demo('5');return false;" /> <input type="button" value="No Match3" onclick="javascript:demo('_');return false;" /> <input type="button" value="No Match4" onclick="javascript:demo('ab12');return false;" /> <br /><br /> <input type="button" value="Match1" onclick="javascript:demo('#ab12');return false;" /> <input type="button" value="Match2" onclick="javascript:demo('#');return false;" /> <input type="button" value="Match3" onclick="javascript:demo('ab_12@#');return false;" /> <input type="button" value="Match4" onclick="javascript:demo('! @#\$%\^&\*\(\)\-\+=~:;<>,.|\{\}\[\]/');return false;" /> <script type="text/javascript" language="JavaScript"> //<![CDATA[ function demo(text) { var re = /\W/; if (text.match(re)) { alert("match"); } else { alert("no match"); } } //]]> </script> |