2010-12-15 103 views

Répondre

2

Utilisation:

/^[-0-9()+x ]+$/ 

par exemple .:

re = /^[-0-9()+x ]+$/ 
match = re.match("555-555-5555") 
2
if (/^[-\d()\+x ]+$/.match(variable)) 
    puts "MATCH" 
else 
    puts "Does not MATCH" 
end 
1

utilisation String#count:

"+1 (800) 123-4567".count("^0-9+x()\\- ").zero? # => true 
"x invalid string x".count("^0-9+x()\\- ").zero? # => false