The regex for money and currency field.


This code is grapping the number  and currency.

   //var txt='200TL';
      //var txt='200 TL';
      //var txt='200 ';
      //var txt='2000$';
      //var txt='2.000.000 TL';
      var txt= '2,000,000 Euro';
      //var txt='20.000.000 TL';
      //var txt='20.000.000';
      //var txt='20.000TL';
      //var txt='20.000.000TL';

      var re1='(\\d*(?:\\.?\\d*\\.?\\d*))';    // Non-greedy match on filler
     
      var re2='((?:[a-zA-Z(?\\s|\\S)]*))';// Word 1
    

      var p = new RegExp(re1+re2,["i"]);
      var m = p.exec(txt);
      if (m !== null)
      {
        document.write(m[1]+" - "+m[2]);      
      }

The result is:
2,000,000 - Euro 


the link is http://jsbin.com/ukizaq/6/

Bu blogdaki popüler yayınlar

SDLC - Software Development Life Cycle

@SerializedName and @Expose annotations