[Angular2 Form] Check Password Match

Source: Internet
Author: User

Learn how to create a custom validator to check whether passwords match.

<H1>Password match</H1><formnovalidate AutoComplete= "Off"[Formgroup]= "Signupform">  <Divclass= "Form-field">    <label>Password:</label>    <inputtype= "text"Formcontrolname= "Password"[(Ngmodel)]= "Signup.password"name= "Password">  </Div>  <Divclass= "Form-field">    <label>Confirm Password:</label>    <inputtype= "text"Formcontrolname= "Confirm"[(Ngmodel)]= "Signup.confirm"name= "Confrim"></Div></form>
    this. Signupform = fb.group ({      password: [        ',        validators.required      ],      confirm: [        ',        [          validators.required,           Confirmpasswordsthis. Signup)        ]    });

Confirmpasword Validator is just a function, also a curry function. So it means it is invoked when we pass the value ' Confirm ' password field.

So if we want to send extra params, we can use '. bind (Undefined, extraparam) '.

Bind to undefined context, would keep the context when it get invoked and then send a extraparam.

The extraparam would be ' passwords ' and the value later being passed in is ' confirm '.

Confirmpassword.ts:

Export function confirmpasswords (passwords, confirm) {  const valid = passwords.password& & passwords.password = = = Confirm.value;   return NULL : {    confirmpassword: {      false,      ' passwrods is notthe ' Same"    }  };}

[Angular2 Form] Check Password Match

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.