jQuery Replace regex


/ Published in: jQuery
Save to your folder(s)

regular expression that removes or replaces input text


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.