English 中文(简体)
如何 使用前线——+ , 价值?
原标题:How To use preg_match for - , + , . values?

I use this preg_match conditions for对正值、负值和贬损数值进行对比

/^[0-9,-.]{1,50}$/

But when I enter --34.000 it does not show error, when I enter 34...9868 it does not show error, what I want is that it must accept only positive, negative and decimal values.

最佳回答

try this regex ^-?d*.?d+$ i suppose it however cannot be limited to 50 chars

问题回答

如果需要核对数字,则最好使用<代码>is_全数()。

你们的reg也完全破碎,因为现在它甚至只能接受包含50个狗的扼杀。

如第123号声明所述,如果有某种投入显示值,则有更好的方法可以发现。 如果你要坚持定期表达的话,你可以采取以下做法:

/^-?[0-9]+(?:.[0-9]+)?$/

Explanation:

  • match start of the string ( ^)
  • match a possible - character (-?); the ? means "not required"
  • match at least one number ([0-9]+)
  • possibly match the whole statement in the parentheses ((?:...)?); ?: means "do not capture the subpattern"
    • a point (.); the . needs to be escaped due to its special function
    • at least one number ([0-9]+)
  • match end of the string ($)

你们需要分开表达,以便它只接受正确地方的特性。 例如:

/^[+-]?([0-9]+,)*[0-9]+(.[0-9]+)?$/

解释这一表述:

<代码>[+-]?: Theeck for a + or - prefix to the number. 它完全是选择性的,但只能是+或-。

([0-9]+,]: 这使一组可选择的 com人数成为可能。 对成千上万的人来说,情况就是如此。

[0-9]+: This requires that the value contains at least some numbers

<代码>([0-9]+)?:最后,这允许有线索的任择术语。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签