Friday, 15 August 2014

jquery - Amount field allowed - only digits 0-9, upto two decimal places and $ -


Hi - I have this Reggae which now gives the user only a key in -09 digits and two decimal places . What should be amended in this reggae to accept '$' also? [Example link for regex] [1]
regex: this.value = this.value.replace (/ ^ (\ d + \.? \ D? \ D?)?. * / G, '$ 1');

Follow your regex:

  ^ (\ d + \. \ D? \ D?)?. *  

You have to add the \ $ symbol like this:

  ^ (\ $ \ D + \.? \ D? \ D?)?. * ^ --- Here, and avoid the character  

BTW, if you do not want to capture Dadar, you can do the symbol:

  ^ (\ $ \ D + \.? \ D? \ D?) ?. *  

No comments:

Post a Comment