Modifying current reg-ex to allow special characters - javascript

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!

Related

Regex password to allow special characters javascript

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.

include a special character (!,#,#,&) not include other special characters

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

Javascript Regex to remove any spaces, special characters and numbers

At the moment I have the following $scope.user.username.replace(/[\s]/g, '');
This removes and special characters and spaces, I need to add in the ability to prevent numbers and special characters too but I can't quite grasp how Regex works.
Would someone be able to help me out?
You should just be able to use not in the matching group and remove everything that isn't a letter:
/[^a-zA-Z]/g
DEMO
Just add the characters you want to remove in the character class:
replace(/[\s.;,?%0-9]/, '')

Javascript regex split for special characters

Have a look at this fiddle http://jsfiddle.net/yeXWv/
Here I want to split the characters which starts with [* or [*# and ends with *]. The current regular expression split the string which starts with [*# but not [*. I have tried the following patterns,
/(\[\*\#*[a-zA-Z0-9]+\*\])/g
/(\[\*\#{0,1}[a-zA-Z0-9]+\*\])/g
Thanks in advance.
Try making the hash character optional:
/(\[\*\#?[a-zA-Z0-9 ]+\*\])/g
Edit: added missing white space :-)
You forgot to allow for spaces, which was the real problem -- not the missing # character.
/(\[\*\#?[a-zA-Z0-9 ]+\*\])/g
That will preserve the [*...*] strings in the output array. To omit them, remove the parentheses:
/\[\*\#?[a-zA-Z0-9 ]+\*\]/g
http://jsfiddle.net/mblase75/zU576/

JS regex name pattern

I need a little help. I want to create a regex pattern in order to validate names, it should contain only letters (any type of letters, non European included), apostrophes, periods, dashes and whitespaces. Or, to put it in another flavor, the regex should not validate any numbers, [], {}, <> etc. Is there a way to to that?
Thank you in advance.
/(\w|\s|[\.\'-])+/
But that's not enough, I guess. Surely we must consider that an apostrophe can not be in the beginning, that several dashes can not follow in a row, etc.
You need a more precise definition of the name.
The Regex you pasted is flawed, it should be
^([a-zA-Z]|\s)*$
Notice the extra parenthesis
Also, You were on the right track but just put all allowed characters in the character class [] :
^([-\w'.\s])*$
a-zA-Z was replaced by the short hand character class for words \w
Add allowed characters as needed

Categories