how to check validation through javascript in asp.net

Posted by Shanky11 under ASP.NET on 12/14/2012 | Points: 10 | Views : 919 | Status : [Member] | Replies : 3
-----------this is the script i had written onkeyup="return validatechar();----------------on textbox

function validatechar() {
var name =document.getElementById('<%=txtname.ClientID %>').value;
var check =/^[a-zA-Z]+$/;
if (!check.test(name.value))
{
alert('Enter name in alphabet only');
}
-------------------------why this is not working ---------------
please find this code and make suitable changes to it if u know but
Don't send link of websites??????????????




Responses

Posted by: Pavanandey on: 12/14/2012 [Member] Bronze | Points: 25

Up
0
Down
function alphanumeric()
{
var letters = /^[a-zA-Z]+$/;
var name = document.getElementById('<%=txtunits.ClientID %>');
if (name.value.match(letters)) {
return true;
}
else {
alert('Please input alpha characters only');
return false;
}
}

<asp:TextBox ID="txtunits" runat="server" onkeyup="return alphanumeric()"></asp:TextBox>

This works

Thanks
Pavan Kumar
Mark Answer if this fits the need

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 12/14/2012 [Member] Bronze | Points: 25

Up
0
Down
Mark the answer if this works

Thanks
Pavan Kumar
Mark Answer if this fits the need

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 12/14/2012 [Member] Starter | Points: 25

Up
0
Down
Try to use the below regular expressions it works

var alpha = /^[(a-z)(A-Z)]+$/;  // Only Alphabets


var alphaSpace = /^[(a-z)(A-Z)(" ")]+$/; //Alphabets with spaces


____________
www.flickr.com/photos/psdesigner/

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response