Re: Search method or RegExp?
- From: Ben Amada <ben.amada@xxxxxxxxx>
- Date: Thu, 30 Aug 2007 15:54:14 -0000
On Aug 30, 1:24 am, "Evertjan." <exjxw.hannivo...@xxxxxxxxxxxx> wrote:
When testing with regex, use test(),
which returns a boolean value.
if (/(\S+@\S+\.\S+)/.test(sEmail)) {
better:
if (/^\S+@\S+\.\S{2,}$/.test(sEmail)) {
Why not use the last one?
return /^\S+@\S+\.\S\S+$/.test(sEmail);
Thanks all ... I looked over all the helpful suggestions, and have it
down to a simple one-liner. Evertjan, the last one you posted right
above didn't seem to like an address such as a@xxx
A boolean return value which the "test" method returns does seem more
intuitive than a check against -1. I'm guessing from the examples
everyone posted that using the "test" or even the "search" methods are
not any less supported by browsers than the RegExp object which I
don't recall anyone including in their examples. At any rate, I'm
going with the following validation test:
function checkEmail(sEmail) {
return (/(\S+@\S+\.\S+)/.test(sEmail));
}
Thanks all,
Ben
.
- Follow-Ups:
- Re: Search method or RegExp?
- From: Evertjan.
- Re: Search method or RegExp?
- References:
- Search method or RegExp?
- From: Ben Amada
- Re: Search method or RegExp?
- From: RobG
- Re: Search method or RegExp?
- From: Ben Amada
- Re: Search method or RegExp?
- From: Evertjan.
- Search method or RegExp?
- Prev by Date: Re: submit() not defined? WTF?
- Next by Date: Re: Search method or RegExp?
- Previous by thread: Re: Search method or RegExp?
- Next by thread: Re: Search method or RegExp?
- Index(es):
Relevant Pages
|