JS calc with eval for YEARS v1
by toubia95
HTML
<input type="text" name="letters" id="letters" value="mille neuf cent soixante douze" placeholder="Année en toutes lettres">
<button type="button" id="button">=></button>
<input type="text" name="numbers" id="numbers">
CSS
/* voir http://stackoverflow.com/questions/5069464/replace-multiple-strings-at-once */
/* voir http://www.regexr.com/ */
/* voir fork v2*/
#letters {
width: 200px;
}
#numbers {
width: 50px;
}
JavaScript
$('#button').click( function() {
var str = $('#letters').val();
str = str.replace(/deux mille/gi, "2000+");
str = str.replace(/mille/gi, "1000+");
str = str.replace(/neuf cent/gi, "900+");
str = str.replace(/huit cent/gi, "800+");
str = str.replace(/sept cent/gi, "700+");
str = str.replace(/six cent/gi, "600+");
str = str.replace(/cinq cent/gi, "500+");
str = str.replace(/quatre cent/gi, "400+");
str = str.replace(/trois cent/gi, "300+");
str = str.replace(/deux cent/gi, "200+");
str = str.replace(/cent/gi, "100+");
str = str.replace(/quatre(-| )vingt(-| )dix/gi, "90+");
str = str.replace(/quatre(-| )vingt/gi, "80+");
str = str.replace(/soixante(-| )dix/gi, "70+");
str = str.replace(/soixante/gi, "60+");
str = str.replace(/cinquante/gi, "50+");
str = str.replace(/quarante/gi, "40+");
str = str.replace(/trente/gi, "30+");
str = str.replace(/vingt/gi, "20+");
str = str.replace(/dix(-| )neuf/gi, "19+");
str = str.replace(/dix(-| )huit/gi, "18+");
str = str.replace(/dix(-| )sept/gi, "17+");
str = str.replace(/seize/gi, "16+");
str = str.replace(/quinze/gi, "15+");
str = str.replace(/quatorze/gi, "14+");
str = str.replace(/treize/gi, "13+");
str = str.replace(/douze/gi, "12+");
str = str.replace(/onze/gi, "11+");
str = str.replace(/dix/gi, "10+");
str = str.replace(/neuf/gi, "9+");
str = str.replace(/huit/gi, "8+");
str = str.replace(/sept/gi, "7+");
str = str.replace(/six/gi, "6+");
str = str.replace(/cinq/gi, "5+");
str = str.replace(/quatre/gi, "4+");
str = str.replace(/trois/gi, "3+");
str = str.replace(/deux/gi, "2+");
str = str.replace(/un/gi, "1+");
str = str.replace(/\+$/igm, ""); // remove last +
str = str.replace(/[^-()\d/*+.]/g, ''); // security
$('#numbers').val(eval(str));
});