Help - Search - Members - Calendar
Full Version: Text field not working
HTMLHelp Forums > Web Authoring > Markup (HTML, XHTML, XML)
tudsy
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
pandy
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.
Christian J
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
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.