Generic way to convert number words to numbers (e.g. "first" to "1st")
<p>i want a  generic  method  using  javascript to  convert </p>

<p>the values like first floor, second floor, ground floor will be converted to below format,</p>

<blockquote>
  <p>Ground Floor: Gr. Floor<br>
  First Floor: 1st Floor<br>
  Twenty floor: 20th Floor</p>
</blockquote>

<p>right now  i am  using  following code
but that not the   correct way as i cannot  write for all the floors (50th floor,90th floor) so please   help me  with this</p>

<pre><code>function validpress(iKeyascii)   
 {
if( iKeyascii=='77'||iKeyascii=='76'||iKeyascii=='68'||iKeyascii=='73'||iKeyascii=='88'||iKeyascii=='86'||iKeyascii=='67')
{
alert("Roman numbers are not allowed.");    
return false;
}   
var txt= document.getElementById('&lt;%=TextBox1.ClientID %&gt;').value;
//document.getElementById('&lt;%=TextBox1.ClientID %&gt;').value = txt.toUpperCase();
 var patternforGFloor = new RegExp('\\b[G|g][R|r][O|o][U|u][n|N][D|d]*\\.*\\s*[F|f][L|l][O|o][O|o][R|r]\\b');
var patternfor1Floor = new RegExp('\\b[F|f][I|i][R|r][S|s][T|t]*\\.*\\s*[F|f][L|l][O|o][O|o][R|r]\\b');
var patternfor2Floor = new RegExp('\\b[S|s][E|e][C|c][O|o][N|n][D|d]*\\.*\\s*[F|f][L|l][O|o][O|o][R|r]\\b');

var patternfor3Floor = new RegExp('\\b[T|t][H|h][I|i][R|r][D|d]*\\.*\\s*[F|f][L|l][O|o][O|o][R|r]\\b');
var patternfor4Floor = new RegExp('\\b[F|f][O|o][U|u][R|r][T|t][H|h]*\\.*\\s*[F|f][L|l][O|o][O|o][R|r]\\b');
var patternfor5Floor = new RegExp('\\b[F|f][I|i][F|f][T|t][H|h]*\\.*\\s*[F|f][L|l][O|o][O|o][R|r]\\b');


     if (txt.match(patternforGFloor) )
     {
     document.getElementById ('&lt;%=TextBox1.ClientID %&gt;').value=txt.replace(patternforGFloor,"Gr.Floor");
     }

      if (txt.match(patternfor1Floor))
     {

     document.getElementById ('&lt;%=TextBox1.ClientID %&gt;').value=txt.replace(patternfor1Floor,"1st. Floor");
     }

     if (txt.match(patternfor2Floor) )
     {
     document.getElementById ('&lt;%=TextBox1.ClientID %&gt;').value=txt.replace(patternfor2Floor,"2nd.Floor");
     }

      if (txt.match(patternfor3Floor))
     {

     document.getElementById ('&lt;%=TextBox1.ClientID %&gt;').value=txt.replace(patternfor3Floor,"3rd. Floor");
     }
  if (txt.match( patternfor4Floor))
     {

     document.getElementById ('&lt;%=TextBox1.ClientID %&gt;').value=txt.replace( patternfor4Floor,"4th. Floor");
     }

if (txt.match( patternfor5Floor))
     {

     document.getElementById ('&lt;%=TextBox1.ClientID %&gt;').value=txt.replace( patternfor5Floor,"5th. Floor");
     }

 }
</code></pre>
