HI daisypricellam,
You need to make changes in Regular Expression as given below.
var regExp = /^[a-zA-Z0-9 ._]+$/;
Refer below code.
HTML
Name:
<input type="text" id="txtName" />
<br />
<br />
<input type="button" value="Submit" onclick="Validate()" />
<script type="text/javascript">
function Validate() {
var regex = /^[a-zA-Z0-9 ._]+$/;
var isValid = regex.test(document.getElementById("txtName").value);
if (!isValid) {
alert("Invalid");
} else {
alert("Valid");
}
return isValid;
}
</script>
Demo