How to check whether entered string contains special characters or not using Jquery
How to check whether entered string contains special characters or not using Jquery. Just drag and drop one text box , button and label control to your asp.net web page. Just change label text as you want. No need to write any server side code to check string contains special characters or not. We need to call one url in top of the page.
How to check whether entered string contains special characters or not using Jquery. Just drag and drop one text box , button and label control to your asp.net web page. Just change label text as you want. No need to write any server side code to check string contains special characters or not. We need to call one url in top of the page. Full source code as follows just try and put your comments to improve these articles.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>How to check whether string contains special characters or not using jquery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function () {
$('#Button1').click(function () {
var strGivenString = $('#TextBox1').val();
if (/^[a-zA-Z0-9- ]*$/.test(strGivenString) == false)
{
alert('Entered String Contains special Characters!');
}
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter The string"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
Dear ultimate,
fallow this code,
function isValid(str) {
var iChars = "~`!#$%^&*+=-[]\\\';,/{}|\":<>?";
for (var i = 0; i < str.length; i++) {
if (iChars.indexOf(str.charAt(i)) != -1) {
alert ("File name has special characters ~`!#$%^&*+=-[]\\\';,/{}|\":<>? \nThese are not allowed\n");
return false;
}
}
return true;
}
farther information please call me 9787373769
Regards,
marudhu....