Skip to content

Commit df12d9d

Browse files
committed
Bug Fixed
1 parent a7b5452 commit df12d9d

File tree

1 file changed

+11
-1
lines changed
  • 42 - Simple Form Validation

1 file changed

+11
-1
lines changed

42 - Simple Form Validation/app.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@ const isPasswordSecure = function(password) {
2828
const format = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})/)
2929
return format.test(String(password))
3030
}
31+
32+
//Only One space between two words will be passed
33+
const isValidUserName = function(username) {
34+
const format = new RegExp(/^([^\s]*[A-Za-z0-9]\s{0,1})[^\s]*$/)
35+
return format.test(String(username).toLowerCase())
36+
}
37+
3138
const validateUsername = function() {
3239
let isInputValid = false
3340
const username = username_input.value.trim()
3441

3542
if (isBlank(username)) {
3643
setError(username_input, "Username can't be blank.")
37-
} else if (!isBetween(username.length)) {
44+
} else if (!isValidUserName(username) ) {
45+
setError(username_input, `Username Invalid`);
46+
}
47+
else if (!isBetween(username.length)) {
3848
setError(username_input, `Username must be between ${min} and ${max} characters.`);
3949
} else {
4050
setSuccess(username_input);

0 commit comments

Comments
 (0)