Categories
Asp, Asp.net

How To Remove Special Characters From TextBox

How To Remove Special Characters From TextBox

Hi guys, in this tutorial i will explain you hot to remove special characters from textbox itself by using javascript.This is cool feature through which we can remove special characters at client side.

Design View:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Hightechnology - Technology That Teach You</title>
<style type="text/css">
.auto-style1 {
width: 900px;
}
</style>
<script type="text/javascript">
function RemoveSpecialChar(txt) {
if (txt.value != '' && txt.value.match(/^[\w ]+$/) == null) {
txt.value = txt.value.replace(/[\W]/g, '');
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1" align="center">
<tr>
<td>
<asp:TextBox ID="txt" runat="server" onkeyup="javascript:RemoveSpecialChar(this)"></asp:TextBox></td>
</tr>
</table>
</div>
</form>
</body>
</html>

One reply on “How To Remove Special Characters From TextBox”

That is a good tip particularly to those new to the blogosphere. Simple but very accurate information?? Thank you for sharing this one. A must read article!

Comments are closed.