Thursday 13 June 2013

Widgets

Only Letters allowed in text Box Using JavaScript.

Description:- Dear Friends in My some previous article We Learned about JQuery Javascript Some Tutorial Like as easeOut Effect in JQueryHow To make Slider in JavaScript,Wait for Downloading Counter,Highlight Searched Text in Gridview,Dropdown list atteched with Selection of another DropDown and many more Article on Asp.net,Css,JavaScript,Html,Jquery.Now In this Article We Learn That How to allowed only Alphabets in textbox Using JavaScript .


Demo:-



Coding:-

<%@ 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 runat="server">
    <title>Aspdotnet Studio</title>
    <script type="text/javascript">
function OnlyAlphabet(){
               if (!FrmText.Letters.value.match(/^[a-zA-Z]+$/) && FrmText.Letters.value !="")
               {
                    FrmText.Letters.value="";
                    FrmText.Letters.focus();
                    alert("Only Alphabets Allowed");
               }
}    
</script>
   
   
   
   
</head>
<body>
   
<table align=center>
<tr><td><form name="FrmText">
Enter Text: <input type="text" name="Letters" onkeyup="OnlyAlphabet()">
</form><br;>
</td></tr>
<script type="text/javascript">document.onload = ctck();</script>
</td></tr>
</table>
</body>
</html>


1 comment:

  1. Hi, its good that the validation works for this...
    But the much better way to do it not allowing the user to enter any value other than alphabets...

    Anyways, thanks for sharing a good example...

    ReplyDelete