Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow `.` in my regular expression? [closed]

I am using this code to prevent entering special chars

String.prototype.isText = function () {return /^[\w\s&'%]*$/.test(this)}

But i want it to allow entering dots in the string.

How can i change it to do that ?

Thanks

like image 479
Utku Dalmaz Avatar asked Dec 02 '22 02:12

Utku Dalmaz


2 Answers

Add a dot:

String.prototype.isText = function () {return /^[\w\s&'%.]*$/.test(this)}
like image 88
phihag Avatar answered Dec 12 '22 00:12

phihag


String.prototype.isText = function () {return /^[\.\w\s&'%]*$/.test(this)}
like image 43
ShaneBlake Avatar answered Dec 12 '22 00:12

ShaneBlake