简体   繁体   中英

Rails format validation — alphanumeric, but not purely numeric

Whats the best way to test a format validation of lets says a username, with a regex for alphanumeric, but not purely numeric?

I've been using the following validation in my model

validates :username, :format => { :with => /^[a-z0-9]+[-a-z0-9]*[a-z0-9]+$/i }

Numeric username's such as '342' pass the validation, which I don't want.

你想要“向前看”一封信:

/\A(?=.*[a-z])[a-z\d]+\Z/i

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM