Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Markup (HTML, XHTML, XML) _ Text field not working

Posted by: tudsy May 2 2018, 12:50 PM

Hi

I am trying to ask a user for their Age (3 numbers) but I am getting the text field greater than 3 chars.


<p align="center">3. Please input your Age:</p>


<input type=“text” name=“Age” required=“required” maxlength=‘3’ size=‘3’ pattern=“[0-9]+” />

Any help will be appreciated.

Tudsy

Posted by: pandy May 2 2018, 04:18 PM

Is that copied from the actual HTML document? In that case it's because you use curly quotes and prim signs. Use normal, straight quotes. And don't use Word and the like to write HTML or any other computer language, as wordprocessors may spiff up what you write with things like this. Use a plain text editor. Only ascii characters are allowed in the actual markup or code in case of programming. Same goes for CSS.

Posted by: Christian J May 3 2018, 12:33 PM

Also the SIZE attribute does not work very well in browsers to control textfield width, use CSS instead.

The PATTERN regex may not work like you want. [0-9] matches the zero character, and the + symbol allows one or more occurence of the character, meaning it allows user values like 0, 00 or 000 (the MAXLENGTH attribute prevents 0000 and longer strings).

See also https://www.regular-expressions.info/numericranges.html

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)