I need to add 2 input types for 1 form field in my html form viz. type=email
and type=number
for the html form field Email/mobile. How do I get this done? Below is the code:
<label for="modlgn-username">Email/mobile</label>
<input type="email" name="email" class="inputbox" size="18" required />
Is it possible to add input type=number
as well in the above code for the same field namely [Email/mobile]?
I'm a beginner and will apprecaite help in the matter a lot
No it is not possible but you can take input type="text" for email/number.
Just to clarify, are you asking if you can assign two input types to the same field?
I have never come across this and pretty sure it isn't possible. The best you can do to capture an email address or a phone number in the same field would be to make the field input type text. However, this would mean that your validation would get a bit harder.
Also, a side note. To ensure your form fields are accessible to users using assistive and adaptive technology (see https://www.w3.org/WAI/tutorials/forms/) you want to make sure that your label "for" and your input "id" values match exactly. In the example below "firstname" is used to do this.
<label for="firstname">First name:</label>
<input type="text" name="firstname" id="firstname">
This will help the screen reader associate the label with the form field.
Cheers,
Choppie