/    Sign up×
Community /Pin to ProfileBookmark

form validation email and zip

What expression that is best use for validating syntax for email and zip-codes (US and canada)

this is what i got for email:

[code]
if (zForm.email.value != (/^(w+@)([a-z0-9-]{2,}.[a-z]{2,})$/i)) {
error += “- Please enter a valid e-mail address n”
}
[/code]

its in a function and called on the onSubmit event… but no matter what email address i use it never works…

and for the zip-code i got

[code]
if (zForm.zipcode.value != /^(d{5}){1}((-d{4})?)$ ) {
error += “- Please enter a valid zip n”
}
[/code]

that for us zips with the optional 4 extra numbers… or at least in theroy… same as before in a function and onSubmit event… what I need to know is why they don’t work, for one. and for two whats the expression for canadian zips?

of couse something like php might be better to validate with… but i don’t know php… i barely know JavaScript… (as u can see)…

any ideas??

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @zygh 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.16,
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,
)...