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}$
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
Not terribly familiar with regex, but I'm guessing it's going to make life much easier for my current need.
I need to validate that a string contains the correct sequence of numbers and letters, so that it always follows the format "AA99999A", where A can be any A-Z character and 9 can be any 0-9 character. Other than exploding the string and validating the characters individually, how would the best way to handle this be?
The result can be a simple true / false as I don't need to specify which characters are incorrect
How about:
preg_match('/^[A-Z]{2}\d{5}[A-Z]$/', $string);
You can try this regex:
'/^[A-Z]{2}\d{5}[A-Z]$/i'
PHP's preg_match will do the trick:
$string_to_be_validated = "AB12345C";
if (preg_match("/\A[A-Z]{2}[0-9]{5}[A-Z]{1}\z/", $string_to_be_validated)) echo "valid";
else echo "invalid";
Here you can find more information on this.
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
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
OK there is an input field for visitor to enter something in it (like nickname lets say). I wish for (upcoming $_POST) variable to have at least (at least) 4 characters before starts to trigger function.
Here is some cosmetic example..
$inputdata = escapeHTML($_REQUEST['data']);
if($inputdata...)
{
//execute $inputdata
}
Any cool trick? Thx!
if (strlen($inputdata) >= 4)
This should work then
Or
if (mb_strlen($inputdata) >= 4) for non-latin text
Resources:
http://www.php.net/manual/en/function.mb-strlen.php
http://php.net/manual/en/function.strlen.php
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
How can I generate md5 string with upper and lowercase letter?
for example: TyUTExUM3Dw
What I’ve tried
$id = $_GET['id'];
$key = "SecreTkEy";
$hash = md5($id.$key);
echo $hash;
The string "TyUTExUM3Dw" is not an MD5 hash, nor anything close to one.
An MD5 hash is a number, and is usually written in hexadecimal which uses 16 digits represented by 0-9 and A-F.
Casing is not important.
The hashes b529d8871187ecc7fe5f152142b3440a and B529D8871187ECC7FE5F152142B3440A are exactly the same.
What is the end goal you're trying to accomplish with your code? If you tell us that we can probably give you a better method to accomplish that.