开发者

Ruby Format Validations [ No Whitespace ]

I'm trying to create a format validation for a text field that will reject anything with whitespace. Can someone help me out with the RegEx syntax? This is what I've tried: 开发者_C百科

no_whitespace = /\A[\S]\z/i

validates :customurl,  :format => { :with => no_whitespace }

I'm new to programming and clueless about RegEx. Any help would be greatly appreciated. Thanks!


Try this:

no_whitespace = /^[\S]+$/

That should specify no whitespace characters from the beginning (^) the the end ($) of the string, and at least 1 character.


Try this:

no_whitespace = /[\S]*/

Use Rubular to help you form and test regular expressions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜