How to trim only alphabets using javascript or jquery -


have scenario need trim alphabets string , display numbers , special characters.

var abc = "hai 40.00"; // output : 40.00 var xyz = "hai 40.00 - 50.00 was" // output : 40.00 - 50.00 

any generic way handle this.

try this:

var xyz = "hai 40.00 - 50.00 was" xyz = xyz.replace(/[a-z]*/gi, '').trim(); alert(xyz); 
  1. [a-z] : match alphabets
  2. * : matches preceding set 0 or more times
  3. g : global flag, not stop after first match
  4. i : case insensetive match
  5. trim : remove leading , trailing spaces

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -