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

Regex to Allow Special Characters, Spaces and Alphanumeric in jQuery

Mar 5, 2014

Here I will explain 
JQuery regular expression to allow special characters, spaces and alphanumeric text or regular expression to allow special characters, spaces and alphanumeric characters in JQuery.

In previous articles I explained
jQuery regular expression to validate url without http(s), regular expression to validate phone number in jquery, regular expression to replace all special characters with spaces in c#, regex email validation in c# and many articles relating to validation, JQuery. Now I will explain regular expression to allow special characters and spaces.

To allow special characters and spaces we need to write the regular expression like as shown below

var re = /^[ A-Za-z0-9_@./#&+-]*$/

If you want see it in complete example need to write the code like as shown below

<html xmlns="">
<title>Regex to allow special characters, spaces and alphanumeric</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(function() {
$('#btnValidate').click(function() {
var txt = $('#txtdesc').val();
var re = /^[ A-Za-z0-9_@./#&+-]*$/
if (re.test(txt)) {
alert('Valid Text')
else {
alert('Please Enter Valid Text');
return false;
Enter Text :<input type="text" id="txtdesc" />
<input type="button" id="btnValidate" value="Validate" />

Live Demo

If you want to test enter special characters like !~

Enter Text :

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

Get the latest,, 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


Rajesh Nair said...

very nice post!
Suresh i have one problem i have to take input from barcode scanner but the textbox should be capable to input multiple barcode values with comma as a separator please help me in this regard
thanks in advance

Anonymous said...

how to write regex to avoid consecutive occurences of special charchers, like '...', '*-', etc?

Anonymous said...

Give your Valuable Comments

Anonymous said...

jQuery regular expression???
isn't it Javascript?

Anonymous said...

Thanks a lot...I used only the expression...with Regex in c#

Unknown said...

Awesome post.Great to visit

Anonymous said...

Great... It works fine

Anonymous said...

its not working for square bracket ]

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

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