Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex Replace anything but numbers and lowercase

I have an input which I am binding to keyup()

On each keyup, I want it to:

  1. disallow any characters that are not a number, a letter, or a dash, and
  2. replace any uppercase characters with lowercase ones.

Regex makes my head explode, any help?

$('.my-input').keyup(function() {
    this.value = this.value.replace(/[^0-9a-z-]/g,/[0-9a-z-]/g);
});
like image 830
wesbos Avatar asked May 27 '11 03:05

wesbos


1 Answers

this.value = this.value.toLowerCase().replace(/[^0-9a-z-]/g,"");
like image 64
ic3b3rg Avatar answered Oct 04 '22 22:10

ic3b3rg