Validation for alphabets only using regular expression
Below script helps to bind the user to enter the value in the text-box which accepts only alphabets
Hi,
Below script helps to bind the user to enter the value in the text-box which accepts only alphabets irrespective of case i.e. it will accepts both lower and upper case alphabets.
To achieve this simply follow the following Steps
Write the below java-script function in the aspx page under head section :
<script type="text/javascript">
function Validation()
{
var a=document.getElementById('<%=TextBox1.ClientID %>').value;
var regex1=/^[a-zA-Z]*$/; //this is the pattern of regular expression
if(regex1.test(a)== false)
{
alert('Please enter data in proper format');
return false;
}
}
</script>
In the Body Section of the .aspx page just bind the onClientClick event of the button to the function above in the java-script to check the value of TextBox1
Take one text-box and button control on the page as shown below
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:return Validation();" />
Regards
S.S.Bajoria