How to program the below text format logic in ruby to validate a text field -


i have text field accepts text satisfies below criteria:

text format of below type 'a' can random alphabets, 'd' numerical digit, last digit sum of other digits modulo 10.

aad-aaa-ddd 

for example:

kn3-mno-41_, means last digit is: 3 + 4 + 1 = 8, becomes: kn3-mno-418 hk5-sfo-32_, means last digit is: 5 + 3 + 2 = 10, becomes hk5-sfo-320 

i in intial learning of ruby, please me: how include these checks in script , validate input text meets criteria.

thanks

def valid?(w)    w.match(/^[a-z][a-z]\d-[a-z][a-z][a-z]-\d\d\d$/i) ,    ([2,8,9].sum {|i| w[i].to_i} % 10 == w[10].to_i) end 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -