Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript regular expression single quotes

My Regex is:

var re = /^[a-z A-Z._]{1,15}$/;

I want to allow this: ' (Single Quote).

How can I do this?

like image 714
Mosh Feu Avatar asked Jul 30 '26 02:07

Mosh Feu


2 Answers

You can use the following regex for example to allow a string like abcd'dfgh:

/^[A-Za-z\/\']+[A-Za-z]$/
like image 109
Rinku Avatar answered Aug 01 '26 16:08

Rinku


To allow single quote, add it in the character class like ^[a-z A-Z._']{1,15}$

This regex allows ' matching 'abc'_, a'b'c_ etc.

like image 22
Naveed S Avatar answered Aug 01 '26 15:08

Naveed S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!