35
Views
2
Comments
regex for restrict backspace button at some point
Question
Application Type
Mobile

Hi All,

I'm working on a mobile application where I'm facing a scenario. I have a input field where I'm filling in the mobile number with country code like (+213). So, If I try to delete the mobile number by using the backspace button, The country code should not be deleted if I continuously press back space button. 

Hope you understand the problem. Any help will be appreciated. 

Thanks 

Prince

UserImage.jpg
Pranav Shingane

Hi, try for this

1) 

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


2) 

var numericReg = /^(?:[a-zA-Z0-9._]|[\b])+$/


3) for numeric

var regExpr = new RegExp("^[0-9,\b][0-9,\b]*$");


4) 

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

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Prince,

First, do you allow changing the country code at all? Is it fixed? If not, how can a user change the country code if not by backspace?

You could consider splitting the country code and phone number in two input fields.

That said, why do you need a regex? How are you going to use it to restrict the input?

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.