<asp:TextBox ID="txtsumassured" runat="server" MaxLength="15" onkeyup="AN_toWords(this.value, 'lblnumtoword', 'lblerrsumass', 'Imgerriconsumass')></asp:TextBox>
//----------It is not applicable for More than 15 digits ---------------------------//
function AN_toWords(MyVal, lblnumbertoword, errmess, erricon) {
document.getElementById(lblnumbertoword).innerHTML = "";
var rVal = MyVal;
var numbers = /^[0-9\,]+$/;
MyVal = MyVal.toString();
MyVal = MyVal.replace(/[\, ]/g, '');
var tempnew = MyVal;
if (tempnew == "") {
document.getElementById(errmess).innerHTML = "Please enter the single premium";
return false;
}
else if (!numbers.test(tempnew)) {
document.getElementById(errmess).innerHTML = "Please enter a valid amount";
return false;
}
rVal = Math.floor(tempnew);
var rup = new String(rVal);
rupRev = rup.split("");
actualNumber = rupRev.reverse();
if (Number(rVal) >= 0) {
}
else {
alert('Number cannot be converted');
return false;
}
if (Number(rVal) == 0) {
document.getElementById(lblnumbertoword).innerHTML = 'Zero Only';
return false;
}
var numWords = ["Zero", " One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", " Nine"];
var numPlace = ['Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', ' Seventeen', ' Eighteen', ' Nineteen'];
var tPlace = ['dummy', ' Ten', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', ' Eighty', ' Ninety'];
var numWordsLength = rupRev.length;
var totalWords = "";
var numtoWords = new Array();
var finalWord = "";
j = 0;
for (i = 0; i < numWordsLength; i++) {
switch (i) {
case 0:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
numtoWords[j] = numtoWords[j] + ' Only';
break;
case 1:
CTen();
break;
case 2:
if (actualNumber[i] == 0) {
numtoWords[j] = '';
}
else if (actualNumber[i - 1] != 0 && actualNumber[i - 2] != 0) {
numtoWords[j] = numWords[actualNumber[i]] + ' Hundred and';
}
else {
numtoWords[j] = numWords[actualNumber[i]] + ' Hundred';
}
break;
case 3:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
if (actualNumber[i + 1] != 0 || actualNumber[i] > 0) {
numtoWords[j] = numtoWords[j] + " Thousand";
}
break;
case 4:
CTen();
break;
case 5:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
if (actualNumber[i + 1] != 0 || actualNumber[i] > 0) {
numtoWords[j] = numtoWords[j] + " Lakh";
}
break;
case 6:
CTen();
break;
case 7:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
numtoWords[j] = numtoWords[j] + " Crore";
break;
case 8:
CTen();
break;
case 9:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
if (actualNumber[i + 1] != 0 || actualNumber[i] > 0) {
numtoWords[j] = numtoWords[j] + " Hundred ";
}
break;
case 10:
CTen();
break;
case 11:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
if (actualNumber[i + 1] != 0 || actualNumber[i] > 0) {
numtoWords[j] = numtoWords[j] + " Thousand ";
}
break;
case 12:
CTen();
break;
case 13:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
if (actualNumber[i + 1] != 0 || actualNumber[i] > 0) {
numtoWords[j] = numtoWords[j] + " Lakh ";
}
break;
case 14:
CTen();
break;
default:
break;
}
j++;
}
function CTen() {
if (actualNumber[i] == 0) {
numtoWords[j] = '';
}
else if (actualNumber[i] == 1) {
numtoWords[j] = numPlace[actualNumber[i - 1]];
}
else {
numtoWords[j] = tPlace[actualNumber[i]];
}
}
numtoWords.reverse();
for (i = 0; i < numtoWords.length; i++) {
finalWord += numtoWords[i];
}
document.getElementById(lblnumbertoword).innerHTML = finalWord;
}
//----------It is not applicable for More than 15 digits ---------------------------//
function AN_toWords(MyVal, lblnumbertoword, errmess, erricon) {
document.getElementById(lblnumbertoword).innerHTML = "";
var rVal = MyVal;
var numbers = /^[0-9\,]+$/;
MyVal = MyVal.toString();
MyVal = MyVal.replace(/[\, ]/g, '');
var tempnew = MyVal;
if (tempnew == "") {
document.getElementById(errmess).innerHTML = "Please enter the single premium";
return false;
}
else if (!numbers.test(tempnew)) {
document.getElementById(errmess).innerHTML = "Please enter a valid amount";
return false;
}
rVal = Math.floor(tempnew);
var rup = new String(rVal);
rupRev = rup.split("");
actualNumber = rupRev.reverse();
if (Number(rVal) >= 0) {
}
else {
alert('Number cannot be converted');
return false;
}
if (Number(rVal) == 0) {
document.getElementById(lblnumbertoword).innerHTML = 'Zero Only';
return false;
}
var numWords = ["Zero", " One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", " Nine"];
var numPlace = ['Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', ' Seventeen', ' Eighteen', ' Nineteen'];
var tPlace = ['dummy', ' Ten', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', ' Eighty', ' Ninety'];
var numWordsLength = rupRev.length;
var totalWords = "";
var numtoWords = new Array();
var finalWord = "";
j = 0;
for (i = 0; i < numWordsLength; i++) {
switch (i) {
case 0:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
numtoWords[j] = numtoWords[j] + ' Only';
break;
case 1:
CTen();
break;
case 2:
if (actualNumber[i] == 0) {
numtoWords[j] = '';
}
else if (actualNumber[i - 1] != 0 && actualNumber[i - 2] != 0) {
numtoWords[j] = numWords[actualNumber[i]] + ' Hundred and';
}
else {
numtoWords[j] = numWords[actualNumber[i]] + ' Hundred';
}
break;
case 3:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
if (actualNumber[i + 1] != 0 || actualNumber[i] > 0) {
numtoWords[j] = numtoWords[j] + " Thousand";
}
break;
case 4:
CTen();
break;
case 5:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
if (actualNumber[i + 1] != 0 || actualNumber[i] > 0) {
numtoWords[j] = numtoWords[j] + " Lakh";
}
break;
case 6:
CTen();
break;
case 7:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
numtoWords[j] = numtoWords[j] + " Crore";
break;
case 8:
CTen();
break;
case 9:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
if (actualNumber[i + 1] != 0 || actualNumber[i] > 0) {
numtoWords[j] = numtoWords[j] + " Hundred ";
}
break;
case 10:
CTen();
break;
case 11:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
if (actualNumber[i + 1] != 0 || actualNumber[i] > 0) {
numtoWords[j] = numtoWords[j] + " Thousand ";
}
break;
case 12:
CTen();
break;
case 13:
if (actualNumber[i] == 0 || actualNumber[i + 1] == 1) {
numtoWords[j] = '';
}
else {
numtoWords[j] = numWords[actualNumber[i]];
}
if (actualNumber[i + 1] != 0 || actualNumber[i] > 0) {
numtoWords[j] = numtoWords[j] + " Lakh ";
}
break;
case 14:
CTen();
break;
default:
break;
}
j++;
}
function CTen() {
if (actualNumber[i] == 0) {
numtoWords[j] = '';
}
else if (actualNumber[i] == 1) {
numtoWords[j] = numPlace[actualNumber[i - 1]];
}
else {
numtoWords[j] = tPlace[actualNumber[i]];
}
}
numtoWords.reverse();
for (i = 0; i < numtoWords.length; i++) {
finalWord += numtoWords[i];
}
document.getElementById(lblnumbertoword).innerHTML = finalWord;
}