JS omit non-numeric characters, when converting time?
- February 4, 2025
- 1 reply
- 731 views
Hello, I am a noob with zero JavaScript training, sorry if my descriptions are confusing.
I am trying to get Time Feilds to convert military time into standard time, so that it displays as H:MM tt. I googled and found a Validation script that seems to work well (attached).
However, I realized soon after, that unless I also type colon ":" I get an error message, and the fields won't recognize that I am trying to input a time. This also happened when accidently typed in a semicolon “;”.
I have used forms in the past that automatically convert '0630' or '630' to "6:30 am" so I knew it was possible to leave out the colon, but as I continued researching it, I am realizing it might not be as simple as I thought.
If possible, I want the fields to only consider numbers when converting to standard time, and also omit or not allow for any non-numeric characters to be typed in. Is this possible to accomplish?
Any and all advice is greatly appreciated, Thanx.
