html character limit

What I'm trying to do is get some input from the user (i.e. Name), but limit the number of characters to more than 5 .... is there any way to do this?

is there also a way to make sure that text input only accepts numbers? (attempt to enter identifier)

 <tr>
   <th>ID:</th>
   <td><input type="text" placeholder="ID" name="studet_ID"></td>
 </tr>
 <tr>
   <th>Full name:</th>
   <td><input type="text" placeholder="Full name" name="studet_name">
 </td>
+4
source share
4 answers
<input pattern=".{5,}" required title="5 characters minimum" type="number">

An input pattern is the easiest way to force a range of characters in a form.

Edit (s):

  • Limited browser support for templates.
  • Use number type for identifier
+2
source

Although you should check the length in the backend (for example, your PHP scripts). There are several ways to do this on the client side.

JavaScript [1] [2] [3], HTML 5: http://www.w3.org/TR/html5/forms.html#the-maxlength-and-minlength-attributes:

<input type="text" name="student_name" minlength=5>

, HTML5.

, , type: http://www.w3.org/TR/html5/forms.html#attr-input-type.

+1

. ( > 5 ).

: . HTML5? , .

... , , "". , .

, . (Javascript) (PHP). Javascript . : , JS - , script (, "" JS-Validation Chrome FF) . . , , , mysql- - , . "" , "SQL-Injection".

, :

if(strlen($_POST['student_ID'])<5) { echo "Error! >5 characters"; }

if(!is_numeric($_POST['student_name']) { echo "Error! Nums only.";}

- , . JS "onchange" ( ) "onblur" ( , , ). JS. , .

, . .

+1

maxlength

Username: <input type="text" name="example" maxlength="10">
-3

Source: https://habr.com/ru/post/1541328/


All Articles