Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex allowing ^ as a input

I have created a regex to only allow characters a-z and A-z. For some reason, the ^ is the only special character that is currently still allowed to be entered as an input. I am not sure why this is happening or how to stop this one character from being allowed to be entered as an input.

console.log( "hello - ^ & world".replace(/[^a-zA-z]/g, '') );

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

A-z is much wider range than A-Z. It includes A-Z, ton of special chars and a-z.

You made a typo (last z should be uppercase), and full regex should look like

/[^a-zA-Z]/g
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading