简体   繁体   中英

How can I match password confirmation by Jquery

I have a jQuery code which going to match passwords from text fields which taken from here . But its not completed. Can any one help me with how to match the password from textfields by this code? Thanks.

Here is my jQuery code segment for password matching. I need to have the logic for "none" part I think.

{
    "confirm": { // password matching
        "regex": "none",
        "alertText": "* Your field is not matching"
    },
    "telephone": {
        "regex": "/^[0-9\-\(\)\ ]+$/",
        "alertText": "* Invalid phone number"
    },
    "email": { // For email validation
        "regex": "/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/",
        "alertText": "* Invalid email address"
    }
}

I think in this code the didn't give the matching loginc in "regex":"none" , part. Can anyone help with this?

In email fields, we will have a @ symbol and . period in general. So, we will match for both of them.

But, in general we allow all characters in password field. So, there is no any special match REGEX we check for that. The only thing I guess we match for is minimum and maximum characters allowed in the password filed.

For example, if we are expecting 8 to 20 characters password, then use the following.

/.{8,20}/

It seems you are writing a generalized validation engine. At first look, we think that we generally check for any fields value and we simply do that using a regex match. But if we further go into it, we may require following in some cases

  1. Password match (Match a field's value with another field) - this is what you exactly needed.
  2. Validate more than two fields with or or and conditions - it seems you are already doing this and state in your validate2fields item
  3. One filed's value should be less than other field's value - Some times we may need to compare two date fields and one should be less than other. or maximum minimum values in some cases.

... and some more.

CodeIgniter PHP framework provides a custom form_validation support and they implemented some generally used validations.

You can find the same here , in Rule Reference Section.

Coming to your point, to match two different fields, you don't need to do any regex match, but you need to provide get the id of other field dynamically in your rules and compare them based on that id.

I suggest, give a type property for each rule and give one of options like

  1. regex - which matches with regex
  2. field - which checks with other field. Give an operator option, which will check for different options.

Hope this gives an idea on what you want to achieve.

Friends, please suggest any better solutions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM