I have been trying to get the following regex to return false if the string has an empty space for the past 3 days. I have read about 24 Stack Overflow postings among other web resources. I’ve take 3 tutorials.
I have been able to return true when there’s at least a number and a letter, and a string between 8 and 24 characters. I have not been able to return false when there is an empty space.
I know that [^S] is supposed to solve the issue, but I haven’t been able to get it to work.
Here’s my function.
function validatePassword(password) {
const pattern = /^(?=.*d)(?=.*[a-zA-Z])^(?=.*s+$).{8,24}$/;
return pattern.test(password);
}
console.log(validatePassword("AlmostBald1 2"));
I have read about 24 Stack Overflow postings among other web resources. I’ve take 3 tutorials.
I have been able to return true when there’s at least a number and a letter, and a string between 8 and 24 characters. I have not been able to return false when there is an empty space.
I have tried adding this piece to my current regex pattern. Examples below:
const pattern = /^(?=.*d)(?=.*[a-zA-Z])^(?=.*s+$).{8,24}$/;
const pattern = /^(?=.*d)(?=.*[a-zA-Z])[^S].{8,24}$/;
I have read (to name a few):
https://regexone.com/lesson/excluding_characters
Detect if string contains any spaces
Regular expression for not allowing spaces in the input field
https://regex101.com/r/zG6Gbz/1
https://www.tutorialspoint.com/validating-a-password-using-javascript#:~:text=To%20validate%20a%20password%20using,the%20password%20matches%20the%20pattern.