Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,071
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Check for Special Characters

    Does this code look right for checking for at least one Special Character in a Password...
    Code:
    	// Check for Special-Character.
    	if (empty($errors)){
    		if (!preg_match("#[\W_]+#", $pass1)){
    			$errors['pass'] = 'Password must have at least 1 Special Character.';
    		}
    	}
    Thanks,


    Debbie

  • #2
    New Coder
    Join Date
    Mar 2013
    Location
    Indiana
    Posts
    26
    Thanks
    0
    Thanked 7 Times in 7 Posts
    PHP Code:
    $string 'foo';

    if (
    preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/'$string))
    {
        
    // one or more of the 'special characters' found in $string

    Credit to chigley from http://stackoverflow.com/questions/3...characters-php

  • #3
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,071
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Chrystyan View Post
    PHP Code:
    $string 'foo';

    if (
    preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/'$string))
    {
        
    // one or more of the 'special characters' found in $string

    Credit to chigley from http://stackoverflow.com/questions/3...characters-php
    That (your) code is also very presumptuous and limiting...


    Debbie


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •