Javascript regular expression: \w |
<input type="button" value="Match1" onclick="javascript:demo('a');return false;" /> <input type="button" value="Match2" onclick="javascript:demo('aa');return false;" /> <input type="button" value="Match3" onclick="javascript:demo('ab_12');return false;" /> <input type="button" value="Match4" onclick="javascript:demo('ab_12@#');return false;" /> <br /><br /> <input type="button" value="No Match1" onclick="javascript:demo('#');return false;" /> <input type="button" value="No Match2" onclick="javascript:demo('##');return false;" /> <input type="button" value="No Match3" 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> |