Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

regex - Laravel validate decimal 0-99.99

Laravel does not have a validation for decimal, so I need a regex or other validation method to validate a numeric value of 0 - 99.99

I have tried

required|regex:^d{0,2}(.d{1,2})?$/
required|regex:[1-9]d?(.dd?)?|0.[1-9]d?||0.0[1-9]
required|regex:/[1-9]d?(.dd?)?|0.[1-9]d?||0.0[1-9]/
required|regex:/[d]{2}.[d]{2}/
required|regex:/[d]{0-2}.[d]{0,2}/

I am either getting "invalid format" when trying to enter 0.05 or unknown modifiers for preg_match

any help with the regex needed to validate a decimal in laravel is appreciated (with optional values before or after decimal

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The laravel(5?) between rule does always get it has to parse a decimal, you have to add numeric to it to validate correctly

'required|numeric|between:0,99.99',

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...