Pages

Wednesday, July 27, 2011

Regular expression to remove all alphabets in a string

Regular expressions are very handly when it comes to working with patterns. In my case working with patterns in javascript. It saves me pile of code that needs to be written in javascript to do pattern based validations.

Following is a simple line of code that helps me to replace all the non digit characters from a string

var pattern=/\D/g
var myStr="80Alpha5Dog5"
alert(myStr.replace(pattern,""))

The answer would be BOSS :)

Hope that helps :)

No comments:

Post a Comment