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

Regular expression to allow + at the start and digits

I have this code.
How I can change it to allow only numbers and + at the start.

$(document).on("input", ".numeric>input , .numeric", function() {
    this.value = this.value.replace(/[^0-9\.]/g,'');
});

Let me know and many thanks!

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

>Solution :

You can easily add the + as the first digit, as i understand you are trying to match a phone number, your code must be as the following :

$(document).on("input", ".numeric>input , .numeric", function() {
    this.value = this.value.replace(/[+0-9\.]/g,'');
});

here is a beautiful online tool where you can build them easily, you do not have to memorise everything :

RegEx

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