0

I'm looking to have an input which can take a frequency in MHz which has multiple decimal separators.

i.e.

14.010.56 MHz

Currently I have the input as

<input type="number" step="any" class="form-control" id="freq" placeholder="Frequency MHz">

but this is only allowing one decimal point to be used as if it were a 'normal' float. Can this be done?

4
  • I'm not familiar with the proper way to write frequencies - is this 14 thousand and ten point 56, or literally 14 point 10 point 56? if the first option, then surely it should be 14,010.56 with a comma. If the second, then this isn't a "number" in the standard sense so cannot be input as such. You would probably need to a normal textbox and validate if with a regular expression instead. Commented Jan 18, 2015 at 17:10
  • its 14 mhz then 10 khz then 56 hz. using a comma how you suggested ie 14,010.56 is the KHz notation, ie 14 thousand and 10 KHz is 14.010 MHz, I'm looking for the MHz notation so guessing reg expression would be required but I've no idea how to form that Commented Jan 18, 2015 at 17:12
  • A notation like 14.010.56 MHz does not match any locale conventions, I’m afraid. It would be misleading and risky to accept it. Commented Jan 18, 2015 at 19:02
  • Not misleading to me which is why I want to use it... Commented Jan 18, 2015 at 19:09

3 Answers 3

1

HTML5 introduces a pattern attribute to the input element, which takes a regular expression which is validated on submit.

The regular expression you need is probably just 1+ digits, then a dot, then 1+ digits, then a dot, then 1+ digits: \d+\.\d+\.\d+:

<form>
    <input type="text" name="freq" placeholder="Frequency MHz" pattern="\d+\.\d+\.\d+" />
    <input type="submit" value="GO" />
</form>

Sign up to request clarification or add additional context in comments.

Comments

0

Can you accept input as a string then split the string to create an array of the three values?

Alternatively, place three inputs in succession separated by "." as is often done with telephone numbers

Comments

0

Use this regular expression

^[0-9]*\.{1}[0-9]*\.{1}[0-9]*$

Comments