求一则正则表达式和另一个正则表达式或检验方法。(撒分,不够另补!)
正则表达式 数字
小弟求大神给一则正则表达式和另一个正则表达式或检验方法,具体情况为:1.有一个这样的输入,要求用户输入的是当天的时间,格式为:9:08,14:23,00:54 这样的格式。请注意小时数可以为一位也可以为两位。
这样的情况下,正则表达式该如何写呢?以及如何用这个正则表达式判断呢?(小弟早就知道正则表达式的厉害,但没有用过,请大神们别见怪)
2.另外一个输入的是,要求用户输入的是钱的数额,格式为:13.04 ;5000; 123.6....。总之,输入的数字可以为小数,也可以为整数;而小数点后可以是一位,也可以是两位,但必须限制在两位以内。一句话,就想判断用户在这里输入的是数字或者带小数点的float,因为后面我要把这些数字来相加的。
我想,是不是有一个神奇的正则表达式可以直接检测?或者马虎点,就直接判断该输入为一个数字就行呢?
求大神给个神奇的正则表达式或者给一个检验方法。
本贴100分,不够我另外赠送分数。
回复讨论(解决方案)
先写个测试钱数额的
//$money = '123';//$money = '12.3';//$money = '123.4';$money = '123.45';//$money = '123.456';//$money = '123456';if( preg_match('/^\d+(\.\d{1,2})?$/',$money) ){ echo $money;}
如果严格测试的话,测试时间的这个用正则来写的话,其实倒是麻烦了不少。
倒不是小时一位两位的问题,而是想36这样的超过合法范围的小时数并不容易检测出来。
if( preg_match('/([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]/',$time) ){
echo $time;
}
大神,先谢过。我马上来测试。
测试成功,谢过,结贴。
如果严格测试的话,测试时间的这个用正则来写的话,其实倒是麻烦了不少。
倒不是小时一位两位的问题,而是想36这样的超过合法范围的小时数并不容易检测出来。
if( preg_match('/([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]/',$time) ){
echo $time;
}
谢过,送分。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.
