Posted By

vagrantradio on 02/16/10


Tagged

regex


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Nymos


jQuery Replace regex


 / Published in: jQuery
 

regular expression that removes or replaces input text

  1. //remove spaces from file name
  2. $('input#file_name').val($('input#file_name').val().replace(/ /g,'_'));
  3.  
  4. //replace special chars
  5. $('input#file_name').val($('input#file_name').val().replace(/[^a-zA-Z 0-9]+/g,''));
  6.  
  7. //replace just letters
  8. $('input#file_name').val($('input#file_name').val().replace(/[^0-9]+/g,''));
  9.  
  10. //replace just numbers
  11. $('input#file_name').val($('input#file_name').val().replace(/[^a-zA-Z]+/g,''));
  12.  
  13. //replace single and double quotes
  14. $('input#file_name').val($('input#file_name').val().replace(/(\'|\")/g,''));

Report this snippet  

You need to login to post a comment.