Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6695475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:13:35+00:00 2026-05-26T06:13:35+00:00

i want a generic method using javascript to convert the values like first floor,

  • 0

i want a generic method using javascript to convert

the values like first floor, second floor, ground floor will be converted to below format,

Ground Floor: Gr. Floor
First Floor: 1st Floor
Twenty floor: 20th Floor

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

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('<%=TextBox1.ClientID %>').value;
//document.getElementById('<%=TextBox1.ClientID %>').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 ('<%=TextBox1.ClientID %>').value=txt.replace(patternforGFloor,"Gr.Floor");
     }

      if (txt.match(patternfor1Floor))
     {

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

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

      if (txt.match(patternfor3Floor))
     {

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

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

if (txt.match( patternfor5Floor))
     {

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

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:13:35+00:00Added an answer on May 26, 2026 at 6:13 am

    First of all, your Regexen are madness. Use the case-insensitive flag /i and use Regex literals so you don’t have to escape everything twice:

    var patternfor1Floor = /\bfirst\s*floor\b/i;
    

    Second, you’ll want find the patterns in the English language and reuse them:

    first, twenty-first, one-hundred-twenty-first
    second, twenty-second, one-hundred-twenty-second
    

    The “first” and “second” parts are repetitive, so you only need to define first through ninth and their values once. The same goes for twenty, thirty and hundred, thousand etc. So you can break down a number like one-hundred-twenty-first into “(one) hundred”, “twenty” and “first” and add the values. “eleven” through “nineteen” are exceptions you’ll need to recognize separately.

    Adding a st, nd, rd or th to the end of the number is trivial by looking at its last digit.

    I can’t and won’t give you a complete solution here, try to get somewhere with this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a generic helper method: def using(closeable: [B has close() method],
I want to create a generic method to serizlize a class to text (for
I want to implement a generic method on a generic class which would allow
Suppose I want to throw a new exception when invoking a generic method with
What would I do if I want to have a generic method that only
I want to determine if a generic object type (T) method type parameter is
I want to have a generic event that I can fire that will take
I want to write a generic function to calculate factorial in C# ... like:
Using SubSonic3, I have this generic method (thanks to linq guy, James Curran): public
I was just trying to code the following extension method: using System; using System.Collections.Generic;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.