Jump to content

Recommended Posts

Good Day,

 

I have created a web page with more than 10 text boxes, i know how to use all validations from vs . now i want to apply validations using Javascript. here are my problems below.

 

1.For Email;

I want a textbox to change border color to red if it is invalid email, belows it is what i have so far..

 

<script type="text/javascript">

 

ar emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}

</script>

 

on the text box;

<asp:TextBox ID="txtEmail" name="email"  onClick="return checkmail(this.myemail)"  runat="server" </asp:TextBox>

 

2.For Numbers

This texbox will only allows numbers only ,I want a textbox to change border color to red if it is invalid input, belows it is what i have so far..

 

<script type="text/javascript">

 

 function numeralsOnly(evt) {
        evt = (evt) ? evt : event;
        var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
           ((evt.which) ? evt.which : 0));
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            alert("Enter numbers only in this field.");
            return false;
        }
        return true;
    }

</script>

 

on the text box;

<asp:TextBox ID="txtFullName" onkeypress="return numeralsOnly(event)"  runat="server"</asp:TextBox>

 

2.For Letters

This texbox will only allows Letters only,I want a textbox to change border color to red if it is invalid input, belows it is what i have so far..

 

<script type="text/javascript">

 

  function lettersOnly(evt) {
        evt = (evt) ? evt : event;
        var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
          ((evt.which) ? evt.which : 0));
        if (charCode > 31 && (charCode < 65 || charCode > 90) &&
          (charCode < 97 || charCode > 122)) {
            alert("Enter letters only.");
            return false;
        }
        return true;
    }

</script>

 

on the text box;

<asp:TextBox ID="txtFullName" onkeypress="return lettersOnly(event)"  runat="server"</asp:TextBox>

 

Thanks for your help.... ::)

 

Link to comment
https://forums.phpfreaks.com/topic/281459-emailnumbers-and-letters-validations/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.