Skip to content

Instantly share code, notes, and snippets.

@arun12209
Created July 5, 2023 04:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save arun12209/059b21021da647213ddee99ae37f9ad9 to your computer and use it in GitHub Desktop.
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