.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Regular Expression for Alphanumeric only for input control

Posted By: priya     Posted Date: December 03, 2009    Points:2   Category :ASP.Net
Hi,

I need Regular Expression for Alphanumeric only for input control. My requirement is user can not enter other than alphanumeric value in a text box.

I am using C# and ASP.net

Thanks In Advance
Priya

Responses
Author: Venkat             
Posted Date: December 04, 2009     Points: 5   

You can use this regular expression for checking alphanumeric.

You can use Regular expression validator control and associate this validation control to the Input TextBox

Expression is

"^[a-zA-Z0-9_*$"


Mark As Answer if this solve your problem
Warm Regards,
Venkat
Author: Prasanti Prusty             
Posted Date: December 17, 2009     Points: 5   

Hi,

You can use Javascripts to validate this as followes.

Define the Function "isNumberEvt" on Head Section. and cakl it on keypress even of text box like "onkeypress="return isNumberEvt(event)"".

<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function isNumberEvt(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode

if ((charCode > 31 && charCode < 48 ) || (charCode > 57 && charCode < 65 ) || (charCode > 90 && charCode < 97) || (charCode > 122))
return false;

return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="238px" onkeypress="return isNumberEvt(event)"></asp:TextBox></div>
</form>
</body>



Regards,
Prasanti


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend