Re: Search method or RegExp?



Ben Amada wrote on 30 aug 2007 in comp.lang.javascript:

function checkSix(sEmail) {
if (sEmail.search(/(\S+@\S+\.\S+)/) != -1) {

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)) {


return true;
} else {
return false;
}
}


if boolean {
return true;
} else {
return false;
};

is the same as:

if boolean {
return true;
};
return false;

is the same as:

return boolean;

Why not use the last one?

return /^\S+@\S+\.\S\S+$/.test(sEmail);

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
.



Relevant Pages

  • Re: Compare a Variable Against Multiple Values
    ... Consider using OrElse instead of Or, as Or will cause all the equations to ... I would use the RegEx as its IMHO the "simplest" & "cleanest" ... wordsAs String) As Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Search method or RegExp?
    ... Ben Amada wrote on 30 aug 2007 in comp.lang.javascript: ... When testing with regex, use test, ... which returns a boolean value. ... don't recall anyone including in their examples. ...
    (comp.lang.javascript)
  • Re: Compare a Variable Against Multiple Values
    ... you need to understand RegEx to be comfortable ... > the routine. ... > wordsAs String) As Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: regular expressions
    ... The hyphen is a special character in a set, you have to escape it: ... Function RegExpValidateas boolean ... Dim RegexObj as Regex = New Regex ...
    (microsoft.public.dotnet.languages.vb)
  • Re: regular expressions
    ... Function RegExpValidateas boolean ... Dim RegexObj as Regex = New Regex ... Dim IsMatch As Boolean = _ ... You do not need to instantiate 'Regex' because 'IsMatch' is a shared method of the 'Regex' class. ...
    (microsoft.public.dotnet.languages.vb)