Question

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??

Was it helpful?

Solution

(\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)

OTHER TIPS

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!

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 .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top