#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Posts
    996
    Rep Power
    15

    simple email validation help


    Hi there,

    I have the following email signup form. The form action is an external website which I don't have access to the code:

    PHP Code:
    <form action="http://external-website.com/form.php" method="post">
    <
    input type="text" name="email" style="width:190px" id="email">
    <
    input type="submit" name="submit" value="submit"

    I would like to add some validation to the form to check that the email is valid. I managed to add some Javascript, which created a prompt, but it also then continued to go to the external URL rather than submitting. Someone mentioned that it's because the submit button is type="submit" and not type="button". However, when I changed it to a button, it didn't do anything.

    Could anyone help me with adding some validation to it?

    Thanks!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    25
    Rep Power
    0
    To attach JavaScript validation to a form you need an eventListener that listens for the submit event. If the validation fails then you need to preventDefault in order to stop the form submitting.

    You don't need to use JavaScript to validate email addresses in modern browsers - simply specifying type="email" instead of type="text" will tell the browser to take care of it for you.

    Comments on this post

    • Kravvitz agrees

IMN logo majestic logo threadwatch logo seochat tools logo