Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:50:15+00:00 2026-06-09T15:50:15+00:00

I would like to ask if there is any way to validate my password

  • 0

I would like to ask if there is any way to validate my password to check if it contains at least 1 alphabet, digit and symbol using zend form validators.

From what I know, there’s only alpha, alphanum etc.: http://framework.zend.com/manual/1.7/en/zend.validate.set.html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:50:17+00:00Added an answer on June 9, 2026 at 3:50 pm

    Here is a custom password validator I use. You can pass an array of options for password requirements, and it can return a string explaining the password requirements based on your options.

    Usage:

    $passwordOpts = array('requireAlpha' => true,
                          'requireNumeric' => true,
                          'minPasswordLength' => 8);
    
    $pwValidator = new My_Validator_SecurePassword($passwordOpts);
    
    $password = new Zend_Form_Element_Password('password', array(
        'validators' => array($pwValidator),
        'description' => $pwValidator->getRequirementString(),
        'label' => 'Password:',
        'required' => true,
    ));
    

    An example requirement string output by the validator looks like:

    Passwords must be at least 8 characters long, contain one digit and contain one alpha character.

    The validator:

    <?php
    
    class My_Validator_SecurePassword extends Zend_Validate_Abstract
    {
        const ALL_WHITESPACE = 'allWhitespace';
        const NOT_LONG       = 'notLong';
        const NO_NUMERIC     = 'noNumeric';
        const NO_ALPHA       = 'noAlpha';
        const NO_CAPITAL     = 'noCapital';
    
        protected $_minPasswordLength = 8;
        protected $_requireNumeric    = true;
        protected $_requireAlpha      = true;
        protected $_requireCapital    = false;
    
        protected $_messageTemplates = array(
            self::ALL_WHITESPACE => 'Password cannot consist of all whitespace',
            self::NOT_LONG       => 'Password must be at least %len% characters in length',
            self::NO_NUMERIC     => 'Password must contain at least 1 numeric character',
            self::NO_ALPHA       => 'Password must contain at least one alphabetic character',
            self::NO_CAPITAL     => 'Password must contain at least one capital letter',
        );
    
        public function __construct($options = array())
        {        
            $this->_messageTemplates[self::NOT_LONG] = str_replace('%len%', $this->_minPasswordLength, $this->_messageTemplates[self::NOT_LONG]);
    
            if (isset($options['minPasswordLength'])
                && Zend_Validate::is($options['minPasswordLength'], 'Digits')
                && (int)$options['minPasswordLength'] > 3)
                $this->_minPasswordLength = $options['minPasswordLength'];
    
            if (isset($options['requireNumeric'])) $this->_requireNumeric = (bool)$options['requireNumeric'];
            if (isset($options['requireAlpha']))   $this->_requireAlpha   = (bool)$options['requireAlpha'];
            if (isset($options['requireCapital'])) $this->_requireCapital = (bool)$options['requireCapital'];
    
        }
    
        /**
         * Validate a password with the set requirements
         * 
         * @see Zend_Validate_Interface::isValid()
         * @return bool true if valid, false if not
         */
        public function isValid($value, $context = null)
        {
            $value = (string)$value;
            $this->_setValue($value);
    
            if (trim($value) == '') {
                $this->_error(self::ALL_WHITESPACE);
            } else if (strlen($value) < $this->_minPasswordLength) {
                $this->_error(self::NOT_LONG, $this->_minPasswordLength);
            } else if ($this->_requireNumeric == true && preg_match('/\d/', $value) == false) {
                $this->_error(self::NO_NUMERIC);
            } else if ($this->_requireAlpha == true && preg_match('/[a-z]/i', $value) == false) {
                $this->_error(self::NO_ALPHA);
            } else if ($this->_requireCapital == true && preg_match('/[A-Z]/', $value) == false) {
                $this->_error(self::NO_CAPITAL);
            }
    
            if (sizeof($this->_errors) > 0) {
                return false;
            } else {
                return true;
            }
        }
    
        /**
         * Return a string explaining the current password requirements such as length and character set
         * 
         * @return string The printable message explaining password requirements
         */
        public function getRequirementString()
        {
            $parts = array();
    
            $parts[] = 'Passwords must be at least ' . $this->_minPasswordLength . ' characters long';
    
            if ($this->_requireNumeric) $parts[] = 'contain one digit';
            if ($this->_requireAlpha)   $parts[] = 'contain one alpha character';
            if ($this->_requireCapital) $parts[] = 'have at least one uppercase letter';
    
            if (sizeof($parts) == 1) {
                return $parts[0] . '.';
            } else if (sizeof($parts) == 2) {
                return $parts[0] . ' and ' . $parts[1] . '.';
            } else {
                $str = $parts[0];
                for ($i = 1; $i < sizeof($parts) - 1; ++$i) {
                    $str .= ', ' . $parts[$i];
                }
    
                $str .= ' and ' . $parts[$i];
    
                return $str . '.';
            }
        }
    }
    

    Hope this helps someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to ask is there any way to achieve this functionality: I
I would like to ask, if there is any way to develop a mouse-over
community! I would like to ask if there is any easy way to determine
I would like to ask if there is any tools for Google App Engine
I would like ask if there's a way to download an android layout from
I would like to ask if there is a way to see a variable
I would like to ask if there is a more elegant way to write
I'd like to ask if there is any way in XSLT to take line
I would just like to ask, is there a way to possibly customize the
I'm new in Android and I would like to ask you is there any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.