/    Sign up×
Community /Pin to ProfileBookmark

Hi, I need help with registration forms. There are two text fields for (email and business website url address).

when person sign up and put website url address, and the email extension address should be match with the website extension address.

For sample that company website name [url]www.amazon.com[/url], and employee email should “[email protected]“.

How can i write the validation code to prevent continue process if website extension address are not same as email extension address!

pleae help thanks.

AM

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mityaMar 13.2011 — HTML
[CODE]<form action='somewhere.htm' method='POST' id='regForm'>
E-mail:<br /><input type='text' id='email' name='email' /><br />
Business URL:<br /><input type='text' id='url' name='url' /><br />
<input type='submit' />
</form>[/CODE]


JS
[CODE] window.onload = function() {
document.getElementById('regForm').onsubmit = function() {
var email = document.getElementById('email').value, url = document.getElementById('url').value, error = false;
var emailDomain = email.match(/@.+$/);
if (!email || !url)
error = 'One or more fields left blank';
else if (!emailDomain)
error = 'Invalid e-mail address entered';
else if (!new RegExp(emailDomain[0].substring(1)+'$').test(url))
error = 'E-mail domain must match website domain';
if (error) {
alert('Error: '+error); return false;
}
};
};[/CODE]


Note this does not rigoruously check for a valid e-mail address or a valid site URL - you'll need to add that. It just illustrates how to achieve what you need re: e-mail domain matching URL domain. Also, at the risk of pointing out the obvious, any validation should be done on the server - never only in the browser.
×

Success!

Help @Alidad spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...