Evaluate a regular expression and another regular expression or test method. (Not enough !) Regular Expression number
The younger brother asks God to give a regular expression and another regular expression or test method, the specific situation is:
1. there is For such input, the user is required to enter the date in the format of 9: 08,14: 54. Note that the hours can be one or two digits.
In this case, how do I write a regular expression? And how to use this regular expression to determine? (The younger brother has long known that regular expressions are amazing, but they have never been used. please be careful)
2. another input is The user is required to enter the amount of money in the format of 13.04; 5000; 123 ..... In short, the input number can be decimal or integer, and the decimal point can be one or two digits, but it must be within two digits. In a word, I want to judge whether the user entered a number or float with a decimal point here, because I will add these numbers later.
I think, is there a magic regular expression that can be directly detected? Or, if you just click it, you just need to judge whether the input is a number?
Please give a magic regular expression or a test method.
This post has a score of 100, which is not enough for me.
Reply to discussion (solution)
Write a test amount first
//$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;}
If we strictly test the time and use regular expressions to write data during the test, it will be a lot of trouble.
It is not a matter of hour or two, but it is not easy to detect hours exceeding the valid range of 36.
If (preg_match ('/([0-9] | 0 [0-9] | 1 [0-9] | 2 [0-3]): [0-5] [0-9]/', $ time )){
Echo $ time;
}
Thank you. I will test it immediately.
The test is successful. thanks and paste it.
If we strictly test the time and use regular expressions to write data during the test, it will be a lot of trouble.
It is not a matter of hour or two, but it is not easy to detect hours exceeding the valid range of 36.
If (preg_match ('/([0-9] | 0 [0-9] | 1 [0-9] | 2 [0-3]): [0-5] [0-9]/', $ time )){
Echo $ time;
}
Thank you! score delivery.