hi,
I have the following pattern to validate email address’s
^(0-9a-zA-Z@(([0-9a-zA-Z])+([-\w][0-9a-zA-Z])*.)+[a-zA-Z]{2,9})$
how can I compare this with a string and return true or false?
thanks
paul
hi,
I have the following pattern to validate email address’s
^(0-9a-zA-Z@(([0-9a-zA-Z])+([-\w][0-9a-zA-Z])*.)+[a-zA-Z]{2,9})$
how can I compare this with a string and return true or false?
thanks
paul
dont worry ive got it
pEmailRegEx =
Regexp.new(/^(0-9a-zA-Z@(([0-9a-zA-Z])+([-\w][0-9a-zA-Z])*.)+[a-zA-Z]{2,9})$/)
@emailArray.delete_if {|email| !pEmailRegEx.match(email)}
paul wrote:
dont worry ive got it
pEmailRegEx =
Regexp.new(/^(0-9a-zA-Z@(([0-9a-zA-Z])+([-\w][0-9a-zA-Z])*.)+[a-zA-Z]{2,9})$/)
@emailArray.delete_if {|email| !pEmailRegEx.match(email)}
You could do that, but it can be MUCH simpler than that
‘[email protected]’ =~ %r{some regex here}
returns true if it’s a match, or false if it’s not.
On Jan 14, 2007, at 15:53 , paul wrote:
hi,
I have the following pattern to validate email address’s
^(0-9a-zA-Z@(([0-9a-zA-Z])+([-\w][0-9a-zA-
Z])*.)+[a-zA-Z]{2,9})$how can I compare this with a string and return true or false?
Converts _pattern_ to a +Regexp+ (if it isn't already one), then
invokes its +match+ method on _str_.
'hello'.match('(.)\1') #=> #<MatchData:0x401b3d30>
'hello'.match('(.)\1')[0] #=> "ll"
'hello'.match(/(.)\1/)[0] #=> "ll"
'hello'.match('xx') #=> nil
–
Jakob S. - http://mentalized.net
paul wrote:
I have the following pattern to validate email address’s
^(0-9a-zA-Z@(([0-9a-zA-Z])+([-\w][0-9a-zA-Z])*.)+[a-zA-Z]{2,9})$
how can I compare this with a string and return true or false?
You can also do it Perl style:
email_address =~
/^(0-9a-zA-Z@(([0-9a-zA-Z])+([-\w][0-9a-zA-Z])*.)+[a-zA-Z]{2,9})$/
–
Michael W.
I wrote:
email_address =~
/^(0-9a-zA-Z@(([0-9a-zA-Z])+([-\w][0-9a-zA-Z])*.)+[a-zA-Z]{2,9})$/
That’s supposed to be on one line, dang word wrap.
–
Michael W.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs