5

enter image description here

form code:

<form class="form"  name ="custRegistration"  id="custRegistration"  onsubmit="return submitAlbum(this)" action="download.jsp" method="post" >


        <p class="email">
            <label for="budget">Expected Budget :</label>
            <input type="text" name="budget"  id="budget"/>
        </p>




        <p class="submit">
             <label for="download" id="freetrail">Download 30 day free trial</label>
            <input type="submit" value="Submit" />
        </p>

    </form>

i want to validate email-ids with the extension which are checked in the above image and block rest of the email-id extensions using javascript..any help would be appreciated??

User2413
  • 605
  • 6
  • 22
  • 51
  • 1
    What do you mean by validate? JavaScipt can only test if the email address is correctly formatted - not whether the email address is in use or not. –  May 13 '14 at 06:24
  • @jeff am asking the same how to test whether the if the email address is correctly formatted. – User2413 May 13 '14 at 06:27
  • meanwhile in related questions: http://stackoverflow.com/questions/46155/validate-email-address-in-javascript?rq=1 – zarkone May 13 '14 at 06:32

3 Answers3

2

(\w+\.)*\w+@(\w+\.)+[A-Za-z]+

this regex is email check basic.

you may use regex for this case, follow regex:

((\w+\.)*\w+)@(\w+\.)+(com|kr|net|us|info|biz)

0

okay , get all the values of checked items in an array (at least this much you should have been able to do by now)

now let the array be ["com","net"]

var arr = ["com","net"];
var str = arr.join("|")
var re = new RegExp("^\w+@\w+\.("+str+")$");
console.log(re);

the regex I have used is the most basic of all, you can change it according to your needs. Another answer on SO suggests "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$" to be a more complete email validator. So you can change your second last line to :

var re = new RegExp("^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.("+str+")$");

this code will give you the regex you need to validate your email.

Now you can simply do regex test to see which emails pass your validation.

happy coding!

aelor
  • 10,892
  • 3
  • 32
  • 48
0

You can also use above regex ( aelor's )as

[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.(COM|ORG|BIZ|CO)  

include your all extentions using pipe separator .

Pramod S. Nikam
  • 4,271
  • 4
  • 38
  • 62