Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to make a number validation that checks if the user hasn't already added the points after each three digits. I plan to do this verification using refex
So for example 11.231.121.313 is a valid number, also 11231121313 but 11231.121.313 is not.
^(\d+|\d{1,3}(\.\d{1,3})*)$
The first alternation allows you to have simply all digits. The second checks for 1-3 digits optionally followed by groups of a decimal point with 1-3 following digits. This works for your examples.
try this
if (preg_match('/^(\d{1,3}(\.\d{3})+|\d+)$/', $number)) {
// correct number
}
UPD: Add expression for only numbers
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Helllo, I wonder if there is a way to compare two strings and get the number of different letters (or any other metrics of difference). strcmp() doesn't really work, since it return some random numbers, which I can't use. My goal is to compare two strings and find if they are different in more than 5 symbols. Can someone give me a hint. Thank you for your time.
Sounds like one of the rare occasions where levenshtein() can be used.
The Levenshtein distance is defined as the minimal number of characters you have to replace, insert or delete to transform str1 into str2.
You could try using PHP's similar_text function:
$matching_char_count = similar_text($var_1, $var_2, $percent);
echo $matching_char_count;
echo $percent;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Looking for regex to do the following in php:
Identify if the given string is in the pattern string1_string2_number e.g ph_val_34563, ph_val_296987 etc.
When true, extract the number part.
regex = "^[A-Za-z]+_[A-Za-z]+_(\d+)$"
Assuming that the valid characters for your strings are letters, [A-Za-z]+ says to expect a group of one or more letters. The _ following these character classes says that an _ must follow.
(\d+) says to group, and capture, a set of one or more numbers following the previous expression.
^ says: "begins with"
$ says: "ends with"
You should take a look at a tutorial on regular expressions.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have been handed a task of putting together a login screen. I found something workable online but I'm having a problem writing the regular expression to validate the password. The following policy should be enforced -- the password should be exactly 14 characters long and should include:
At least 2 upper case letters,
at least 2 lower case letters,
at least 2 numbers, and
at least 2 'special' characters
I have no idea how to write this. Can anybody help?
Assuming by "special characters" you mean anything that isn't a letter or number:
^(?=.*[a-z].*[a-z])(?=.*[A-Z].*[A-Z])(?=.*[0-9].*[0-9])(?=.*[^A-Za-z0-9].*[^A-Za-z0-9]).{14}$
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to retrieve a list of words, but don't want any words that contain a number or numbers in them.
The idea is very simple, but I'm not even sure how to try. I have one column of words some of which have numbers in them. I only want to retrieve the ones without numbers.
How would I do this in my SQL query?
Thanks
Use a regular expression, either with php's preg_match, or with REGEXP in mysql.
SELECT list_col FROM list_table WHERE list_col NOT REGEXP '[0-9]'
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to build a regular expression for a specific problem but I cannot achieve to do it. I have a structure of a string like this 01422756860-8.
As you can see there is a string of length 13. The first 11 characters should be numbers in the interval of [0-9], the next character is a line(minus) and the last character is again a number. There shouldn be any space in between these characters.
Could anyone please help me to do this? I am going to use this regex in php.
I look forward on your answer.
Thank You.
What's the problem?
/^[0-9]{11}-[0-9]$/
Demo
Autopsy:
^ The string must start here
[0-9]{11} Any digit from 0 to 9 repeated exactly 11 times
- A literal dash
[0-9] Any single digit from 0 to 9
$ The string must end here
This regular expression should do it
\d{11}-\d