-
-
Save arun12209/059b21021da647213ddee99ae37f9ad9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement, track } from 'lwc'; | |
export default class PasswordValidationExample extends LightningElement { | |
@track password = ''; | |
@track passwordError = ''; | |
handlePasswordChange(event) { | |
this.password = event.target.value; | |
this.validatePassword(); | |
} | |
validatePassword() { | |
if (!this.password) { | |
this.passwordError = 'Password is required.'; | |
} else if (this.password.length < 8) { | |
this.passwordError = 'Password should be at least 8 characters long.'; | |
} else if (!/[A-Z]/.test(this.password)) { | |
this.passwordError = 'Password should contain at least one uppercase letter.'; | |
} else if (!/[0-9]/.test(this.password)) { | |
this.passwordError = 'Password should contain at least one numeric digit.'; | |
} else { | |
this.passwordError = ''; | |
} | |
} | |
handleSubmit() { | |
if (!this.passwordError) { | |
// Form is valid, perform submission logic | |
// ... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment