SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do i validate an email address in a prompt box

    Trying to make a 2 page application. First is an introduction page and second is the content. Ive put a pop up box in the head of the second page and it asks for email, but how do i make it so if the email is incorrect it will not go onto the second page? at present if i click the link for the second page the box pops up but that is it. I can document.write their response and it comes on the top of the second page, but i want it validated! Any ideas?

    Alan.

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hy
    You can use the match('regexp') method. It returns the matches or null.
    Here is an example:
    Code:
    <script type="text/javascript"><!--
    var str = "abc@defg.hy";
    var regx = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/gi;
    if(str.match(regx)!=null) alert(str.match(regx));    // on
    --></script>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •