We help IT Professionals succeed at work.
Get Started

Can a javascript regular expression help clean up these odd formats?

Last Modified: 2015-09-15
Objective: Clean up/format value in javascript variable zheight_feet_and_inches before attempting to use it for calculations:
      Desired format  5' 4"   (This is what my calculation code expects.  It works properly when the numbers are received in this format.)

      Unexpected formats examples:  
         4' .5"
         5' 5.5"
         5' 11.5"
         5' 5.354"

(Numbers come from an external system over which I have no control.)    

I know I could write several if statements and string functions to clean these up,
but I know just  enough about regular expressions to think one might be useful here and save me
writing a lot of code.   But I have no idea which one or even how to write them in javascript.  

Can someone help me out here?
Watch Question
Top Expert 2004
This problem has been solved!
Unlock 3 Answers and 8 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE