Check string contains special characters using Javascript
Introduction: Hello Friends!! In this article I will explain about the implementation to check whether string contains special characters using Javascript.
Implementation: The HTML page there will be two controls one is TextBox for submitting input by the user. And other is button to validating or checking the string. Here we will assign javascript onclick event handler to the button.
Name:<input type="text" id="text_string" />
<input type="button" value="Submit" onclick="Validate)string()" />
When user will click the Button, the Validate javascript function will be call automatically. If entered string by the user i.e. TextBox value any character other than Alphabets, Numbers or Space then it will be as invalid and a error message will be displayed Error Message Box.
<script type="text/javascript">
function Validate_string() {
//Regex for Valid Charactersi.e. Alphabets, Numbers and Space.
var regex = /^[
//Validate TextBox value against the Regex.
var isValid = regex.test(document.getElementById("text_string").value);
if (!isValid) {
alert("There is Special Characters");
}else {
alert("There is no any Special Characters");
}
return isValid;
}
</script>
Conclusion: In above code, I explained that how to check whether string contains special characters using Javascript. This code is very helpful for every developer. Bye Bye everyone and take care of you Developers. We will come back shortly with the new article.
Regards
Using Asp.net
Comments
Post a Comment