I am using the following regex (got it from here) to verify passwords:
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{6,}$/
I'm not too familiar with regexpressions, but how would I allow this to allow for special characters like !##$%^&*?
Thanks!
Simply add the other characters you want to the part inside the brackets.
The resulting regex is:
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z!##$%^&*?]{6,}$/
Regex101 Tested
I think that this regular expression /^[\w!##\$%\^&\*\?]{8,}$/ will match what you need if the all the special characters you want to include are the ones you mentioned and you want a password of at least 8 characters.
Related
I have this reg-ex to validate comma separated values:
regex = "/^[-\w\s]+(?:,[-\w\s]+)*$/"
Currently there are no special characters allowed.
What modification to this can be made to allow special characters in each comma separated value?
Just add wanted special characters inside the character class like, for example:
/^[-\w\s#|#%]+(?:,[-\w\s#|#%]+)*$/
// ^^^^ ^^^^
You can add any character you want.
#Harman,
I cannot suggest edits in your regex, but I have one regex which I used sometime back in my code to incorporate special characters too.
Try this one:
(?:^|,\s{0,})(["]?)\s{0,}((?:.|\n|\r)*?)\1(?=[,]\s{0,}|$)
You can try this regex here
Hope this will be helpful for you!
I have this simple regular expression for Emails.
/^[a-z]+([\.-_]?[a-z0-9]+)*#([a-z]{3,})+(\.[a-z]{2,3})+$/i;
But when I use this example: first#last#example.com it's still works, And Also when I remove # character from expression :
`/^[a-z]+([\.-_]?[a-z0-9]+)*([a-z]{3,})+(\.[a-z]{2,3})+$/i
it gives the same result.
This expression allows an infinite number of at signs (i.e. #) between at least 2 characters in the email !!
Where is the problem with this expression?
Your pattern is rather restrictive, you might think of other options of validating an email address, like type="email" if it is an input field validation.
As to why the regex matches # even if you take it out, or matches a string with two # symbols, that is cased by [.-_] that matches a lot of chars as the hyphen creates a range that includes #. You need to use [._-] instead.
You may "fix" the regex as
/^[a-z]+([._-]?[a-z0-9]+)*[a-z]{3,}(\.[a-z]{2,3})+$/i
However, this regex is not good to use in real life scenarios.
You want something like that?
/^[a-z\.\-_]+#([a-z]{3,})+(\.[a-z]{2,3})+$/
Probably with sign \.-_ you wanted to have either ".", or "-" or "_" to be used inside the regex, but you forgot to escape "minus".
Or you can use your own but with escape:
^[a-z]+([\.\-_]?[a-z0-9]+)*#([a-z]{3,})+(\.[a-z]{2,3})+$
PS: Remember that a real valid email address could be completely different and has a huge regex, and moreover, each web server defines what is allowed and what is not in email.
I am trying to validate a text box where user will only be allowed to enter alphabets,number,and few special characters like !, #, #, $, %, &, * currently I tried only [a-zA-Z0-9] which accepts only alphabets And number,can someone please suggest me a regex which will help me to get the same.
/^[a-zA-Z0-9!##$%&*]+$/g should work for you. This will validate if the the complete string is composed of one or more characters found within the square brackets.
To familiarize yourself with some regular expressions syntax and meaning, I would suggest using RegExr. This provides an online validator, explains each element of the expression and has helpful tips/examples in the side bar to help with expression building.
/[a-zA-Z0-9!##$%]$/g.test('aaaaa!jbhjj###')
i want to test the password field and will update the html for result.
One of them is:
include a special character (!,#,#,&) not include other special characters
i have test first condition like this
reg= new RegExp('(?=.*[!##&])');
var regexmatch=reg.test(password);
can anyone tell me how to test this condition in one regex
From what I understand, you mean this:
/^[a-z\d!##&]+$/i
This only allows letters, numbers and the 4 symbols.
(?=.*[!##&])(?!.*[^!##&])
This should do it for you.The negative lookahead will not allow other special characters.
reg= new RegExp('(?=.*[!##&])(?!.*[^!##$])');
var regexmatch=reg.test(password);
If alphanumerics is allowed
^(?=.*[!##&])(?!.*[^!##&a-zA-Z0-9\n])[a-zA-Z0-9!##&]+$
Try this.See demo.It will allow only alphanumerics and !##&.
https://regex101.com/r/eS7gD7/32
I'm trying to validate this regular expression with JavaScript. What I need it to do is check if at least 2 words are entered. By words I mean strings with any characters except some specific. Everything is good until I end a string with a special unicode character, such as "ā". Then the expression fails to validate. Currently the expression looks like this -
/^([^<>\\\/\?&{};#{}\+\*()"=%#,:0-9]{1,}\w){2,}$/i
Any ideas on how to validate unicode expressions in this case?
On most programming lang, you would try this Unicode Regex:
/^([^<>\\\/\?&{};#{}\+\*()"=%#,:0-9\s]{1,}\p{L}){2,}$/ims
Or like this
/^([^\P]{1,}\p{L}){2,}$/ims
However, JS doesnt support Unicode that easily :(
See here for example: Javascript + Unicode regexes