Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Introduction:

Here I will explain how to check if string contains special characters in
jQuery or jQuery check if string contains special characters.

Description:


To check if string contains special characters we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Check if string contains special characters or not</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function () {
$('#btnClick').click(function () {
var str = $('#txtName').val();
if (/^[a-zA-Z0-9- ]*$/.test(str) == false) {
alert('Your String Contains illegal Characters.');
}
})
})
</script>
</head>
<body>
<form id="form1">
<div>
Enter Search:<input type="text" id="txtName" />
<input type="button" id="btnClick" value="Check" />
</div>
</form>
</body>
</html>
Once we run above query we will get output like as shown below

Live Demo

To check live demo enter text with special characters and click on below button


Enter Search:

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

1 comments :

sakthideveloper said...

hi suresh, in some browser the script is disable by user. in this time the script will not work. Is any way to enable the script programatically?

i searching solution for this. can you help me?

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.