how to add email adress validation code so the validation will dispaly after immideately entered email adress in text box of email adress

Recommended Answers

All 8 Replies

Can be done via JQuery

Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        TextBox1.BackColor = Color.White
        Dim temp As String
        temp = TextBox1.Text
        'Dim conditon As Boolean = False
        If emailaddresscheck(temp) = True Then
            ': If emailaddresscheck(conditon) = True Then
            TextBox1.BackColor = Color.Green
        Else
            'MessageBox.Show("Please enter your email address correctly", "Incorrect Email Entry")
            'TextBox1.Text = ""
            TextBox1.BackColor = Color.Yellow
        End If

    End Sub

I have stopped the message cause it will never allow to enter valid email unless you copy and paste.

Also try this pattern

Dim pattern As String = "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

Regards,

@GarryHillton why do you post .NET code in a php thread? This is just spam...
On topic: you can use javascript to validate the email address immediatly.
This can be used to check if the email address is in a valid format ( http://www.marketingtechblog.com/javascript-regex-emailaddress/ )

If you need additional validation (checking that an email address is not already in use in your application, ..) you should use AJAX to connect back to the server and check this. You can either use raw AJAX but I advise you to use Jquery instead as it deals with the low level details of AJAX.

It is a Accidently happened.

U need the latest jquery may be jquery-1.7.2.js

http://code.jquery.com/jquery-1.7.2.js

& validation library

http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js

and few codes in javascript

<script type='text/javascript'>

$(document).ready(function(){

// Validation

 $("#yourForm").validate({
 rules:{
 email:{required:true,email:true},
 },

messages:{
email:{
 required:"Enter your email address",
 email:"Must be valid email address"},
 }
 });
 });
 </script>

'yourForm' is the id of your form...I have given u directions and almost 90% of script.....Rest is on your part to include proper error class and success class in the code above and proper css for the success and error class...try to learn jquery which makes good on page events....if you learn it you can even submit the form in the same page.

It's a great tutorial.every step has been expialned in a very simple way.Esay to be followed by anyone.

i m asking about how to write code in php to give a proper message of validation for email address after entered email adress text box

In php you can validate only if the form is submitted not after entering the text inside form...
Your question directed me towards jquery...

in php u can do it by

if(empty($_POST['email'])){
    echo "Email Field Empty!";
    exit;
}
    if(!filter_var($_POST[email], FILTER_VALIDATE_EMAIL))
{
exit("Please Enter Valid Email id");
}

Above two Snippets will do it!

Please Post your question properly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.