
JavaScript regex validate Character.

<html>
<head>
<title>Character validation using regex</title>
<script type="text/javascript">
function validate() {
var name = document.getElementById("name").value;
var pattern = /\w/;
if (pattern.test(name)) {
alert("Inputed Character value : "+name);
return true;
}
alert("It is not valid character !");
return false;
}
</script>
</head>
<body>
<h2>Validating Character..</h2>
Enter Any character value :
<input type="text" name="name" id="name" />
<input type="submit" value="Check" onclick="validate();" />
</body>
</html>
The above example validate character value by using regular expression- /\w/
Here /../(forward slashes) is used to quote your regular expression.
\w shows the word character as all alphabet, numbers and underscore.
test() method takes one argument and check that to the pattern.