开发者

Ruby Format Validations [ No Whitespace ]

开发者 https://www.devze.com 2023-03-19 19:30 出处:网络
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百科

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

精彩评论

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