10 examples of 'username validation in javascript' in JavaScript

Every line of 'username validation in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
10function validateUsername() {
11 var username = $('#username').val();
12 console.log(username);
13
14 if (username.match(nameRegex) != null) {
15 if (username.length <= 8) {
16 window.location.replace('/chat/' + username);
17 } else {
18 alert("Username is not valid. Maximum 8 characters allowed.");
19 }
20 } else {
21 alert("Username is not valid. Only characters letters, numbers and '_' are acceptable.");
22 }
23};
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

73function checkUsername(username){
74 var reg=/^[0-9A-Za-z_]{6,}$/;
75 if(username.match(reg))
76 return true;
77 return false;
78}
1function validateUsernameInput(username) {
2 if (!username) {
3 throw new Error('Username required as input');
4 }
5 if (typeof username !== 'string') {
6 throw new Error('Add username as string');
7 }
8}
181public async validatePassword(password: string): Promise<boolean> {
182 try {
183 const isMatch = await bcrypt.compare(password, this.password);
184 return isMatch;
185 } catch (error) {
186 return error;
187 }
188}
32function isValidUsername(username) {
33 return username && username.length >= USERNAME_MIN_SIZE && !forbiddenCaracters.test(username);
34}
10function validateEmail (email) {
11 if (email && email.match(/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i)) {
12 return true
13 }
14
15 return false
16}
36isValidEmail() {
37 // to validate email we could use joi (only put this in an info box)
38 return this.state.email;
39}
94private async validateUser(email: string, password: string): Promise<any> {
95 const user: User | undefined = await this.userService.findOneByEmail(email);
96
97 if (user && await bcrypt.compare(password, user.password)) {
98 const { password, ...result } = user;
99 return result;
100 }
101
102 return null;
103}
20function validate_email(email)
21{
22 var emailReg = /\S+@\S+\.\S+/;
23
24 if(!emailReg.test(email)) {
25 return false;
26 }
27
28 return true;
29}
13async validateUser(username: string, pass: string): Promise<User | undefined> {
14 const user = await this.usersService.findOne(username);
15 if (user && (await compare(pass, user.password!))) {
16 return classToPlain(user) as User;
17 }
18 return undefined;
19}

Related snippets