I am trying to use the following regex to check if a string is a positive decimal number or 2:
^\d+(\.(\d{2}))?$
When I try to match this using preg_match, I get an error:
Warning: preg_match (): trailing delimiter '^' found in /Library/WebServer/Documents/lib/forms.php on line 862
What am I doing wrong?
The error is that there is no delimiter /or #etc., make sure you enclose the regex expression in delimiters:
/
#
if (preg_match('/^\d+(\.(\d{2}))?$/', $text)) { // more code return true; }
Or:
if (preg_match('#^\d+(\.(\d{2}))?$#', $text)) { // more code return true; }
PHP preg , /; , /[a-z]/ a z. "^\\d+(.(\\d{2}))?$", \\d+(.(\\d{2}))?$, ^ s, ^. , , , "/^\\d+(.(\\d{2}))?$/". , , - .; , , ; \.. "/^\d+(\.(\d{2}))?$/". , , "/^\d+(?:\.(\d{2}))?$/", $1 $2.
preg
/[a-z]/
a
z
"^\\d+(.(\\d{2}))?$"
\\d+(.(\\d{2}))?$
^
"/^\\d+(.(\\d{2}))?$/"
.
\.
"/^\d+(\.(\d{2}))?$/"
"/^\d+(?:\.(\d{2}))?$/"
$1
$2
Source: https://habr.com/ru/post/1749711/More articles:Asp.net Extension CompareValidator - validationВнештатный сайт - Концепция сделки - escrowNoMethodError for time_zone_select in form - timezoneI want to track logs using the multi parameter of the macro is always null. problems C ++ windows - c ++Java - javaAmazon Apache Server Web Services - amazon-s3Custom context menu with Javascript? - javascripthaml / rails: title of a lesson with German umlauts - ruby-on-railsIs it possible to debug a special version of an iPhone application on an iPhone using Xcode? - iphoneASP.NET MVC / VS: How to stop VS by inserting automatic identifiers in the inserted form? - visual-studioAll Articles