Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regular expression in javascript which allows backspace

My regular expression which allows characters, numbers, dot and underscore is

var numericReg = /^[a-zA-Z0-9\._]+$/;

How could i allow backspace in this reg ex.?

like image 548
Amith Avatar asked Jan 23 '13 06:01

Amith


1 Answers

You can use [\b] to match backspace. So, just add it to your character class: -

var numericReg = /^[a-zA-Z0-9._\b]+$/;

Note that you don't need to escape dot (.) in character class. It has not special meaning in there.

See also: -

  • http://www.regular-expressions.info/reference.html

for more escape sequences, and patterns in Regex.

like image 64
Rohit Jain Avatar answered Sep 29 '22 16:09

Rohit Jain