jQuery Check Textbox Value – How to check if a textbox contains a Character in jQuery?

In this article, you going to see discussion regarding jQuery Check Textbox Value which is Character in details and step by step.

If you are looking for this topic then you are at right place.

Let’s start with the topic of jQuery Check Textbox Value which is Character

It is very easy to check if textbox contains a character in jQuery.

In case of jQuery, it is important to jQuery lib in the header.

Add textbox for checking character using jQuery.

Next step is to add the button.

To get the value from the textbox, click on the button.

To check the value, which we are fetching from textbox use regular expression for it.

Below is regular expression code snippet for checking character from textbox.

var regexname=/^([a-zA-Z0-9]{3,16})$/;

Below is the complete code snippet from which you can understand.

<!DOCTYPE html>
<html>
<head>
	<title>How to check if textbox contains a Character in jQuery?</title>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
</head>
<style type="text/css">
.popupDIv{
    border: 4px solid #6b6a63;
    width: auto;
    border-radius :7px;
    margin : auto;
    padding : 20px;
    position:fixed;
}
</style>
<body>
<div style="background-color:#e5bcbc;padding:10px;" align="center">
	<h2>How to check if textbox contains a Character in jQuery?</h2>
	<input type="text" id="txtVal" class="txtVal" name="txtVal" value="">
	<button class="txtBtn">Check Text Value</button>
	<div>Checked the Text Value :<span class="getVal"></span></div>
	<div>Result :<span class="resVal"></span></div>
</div>
</div>
<script>
$(document).ready(function(){
	$(".txtBtn").click(function(){
		var varVal = $(".txtVal").val();
		var regexname=/^([a-zA-Z0-9]{3,16})$/;
		$(".getVal").text(varVal);
		if(varVal.match(regexname)){
			var rseVal = '  "'+varVal+'" : Not contain Special Charaters';
			$(".resVal").text(rseVal);
		}else{
			var rsVal = "Contain Special Charaters";
			$(".resVal").text(rsVal);
		}
			
			
	});
});
</script>
</body>
</html>

OUTPUT 1 :

Not contain special character - jQuery Check Textbox
Not contain special characterjQuery Check

OUTPUT 2 :

Contain Special Character : jQuery Check
Contain Special Character : jQuery Check

The solution to jQuery check is null or empty

Conclusion :

Use the above code to Check Textbox Value which is character.

I hope you like this article and if you think that i have missing something, please comment below.

Leave a Reply