Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

XML
<script language="Javascript">
function AllowAlphabet(e)
{
document.getElementById("div_name").innerHTML="";
    document.getElementById("div_name").style.display="none";

  isIE = document.all ? 1 : 0
  keyEntry = !isIE ? e.which : event.keyCode;
  if (((keyEntry >= '65') && (keyEntry <= '90')) || ((keyEntry >= '97') && (keyEntry <= '122')) || (keyEntry == '46') || (keyEntry == '32') || keyEntry == '45')
     return true;
  else
{
   document.getElementById("div_name").innerHTML="<B>Enter only Characters</B>";
            document.getElementById("div_name").style.display="block";

    return false;
      }
}
</script

>
c# code:
C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class FO_MASTER : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txt_FieldOfficerName.Attributes.Add("onkeypress", "AllowAlphabet(e)");
}
    }

anybody solution me,please hlep me
Posted
Updated 17-Jun-13 0:32am
v3

Use this regex code :
"onlyLetterNumber": {
"regex": /^[0-9a-zA-Z]+$/,
"alertText": "* No special characters allowed"
},


Thanks
prince Sharma
 
Share this answer
 
Comments
Member 9959371 17-Jun-13 4:14am    
I don'not know above code ,,plz send me correct code
<script language="Javascript">
$(document).ready(function(){

$('btn').click(function(){
var txtvalue=$('#txtName').val();

var regex= /^[0-9a-zA-Z]+$/;

if(regex.test(txtvalue))
{
//true and allow it..type your code here

}
else
{
alert('Allow only characters');
}

});

});

</script>



These lines of code written in jquery. so add jquery library to run it. or give me your email id. i will mail you demo project.

Thanks
Prince Sharma
Software Developer
ASP.NET
 
Share this answer
 
<html>
<head>
<script type="text/javascript">
function charOnly()
{
var strtext=document.getElementById("textbox").value;
var index=strtext.length;
for(var i=0;i<index;i++)
{
var asciiValue=strtext.charCodeAt(i);
if(asciiValue>=65&&asciiValue<=90 || asciiValue>=97 && asciiValue<=122)
{
alert("Char is entered");
}
else
{
alert("invalid data is entered");
}
}
}

</script>
</head>
<body>
Enter any value:<input type="text" id="textbox"/>
<button onClick="charOnly()">Check For Valid Characters</button>
</body>
</html>
 
Share this answer
 
Why to stick wid JavaScript???

have a look at the following...

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/FilteredTextBox/FilteredTextBox.aspx[^]


Hope you gonna like it...

:)
 
Share this answer
 
Comments
VICK 18-Jun-13 8:51am    
Thanks for Accepting it as answer... :)
You need to filter the input while user is entering it. You can use this framework for this. It already has these functionality built in you just need to see how it can be used to achieve this functionality.

A Tiny Javascript Framework for Common Validation Scenarios.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900