When setting a character limit in the input field

Asked 2 years ago, Updated 2 years ago, 75 views

Hello
When creating a shopping site and displaying errors in the shipping address information,
I'd like to limit the number of characters. For example: Phone numbers range from 8 to 10 characters.
I've looked at various sites, but I don't understand it a little bit because it turned out to be ???.
I would like to write it in the HTML below.
How should I describe it?I would appreciate it if you could let me know.

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<metacharset="UTF-8"/>
<title> Error indication</title>
<link rel="stylesheet" type="text/css"href="/style.css">
</head>
<body>
<th:blockth:fragment="InformationError">
    <divid="InformationError" title="Input Error" class="hidden">
        <div class="errorNameError">NAME</div>
        <div class="error TelNoError hidden"></div>
    <div class="errorAddressError hidden"></div>
    </div>
</th:block>
</body>
</html>

html spring-boot

2022-09-30 18:06

4 Answers

Check string length in for user convenience only.

Attackers can POST long strings without using , so they can POST long strings without using


2022-09-30 18:06

Nice to meet you.Typical methods include:
How it works and how it works depends on the tool you use

  • Specify maxlength and pattern for input tags in the form
  • Read the form in JavaScript and check the input.
  • Check the server side of the program for input
  • Restricting on the database side

However, it is appropriate to check the server side program at least immediately before entering the incorrect value in the database.
Front-end checks are important to enhance the user experience, but relying on them can result in incorrect values.


2022-09-30 18:06

The ability to count the number of characters entered can be achieved with programs written in Javascript and other places.

To check if your input meets the Check the number of characters entered in the submission form page, you can use it as a reference.


2022-09-30 18:06

  • validation, validation, validation
  • constraint, constraint

I think it will be called a function, but as others have answered, there are several ways to realize it, so I think it will be difficult to provide a specific solution to the current question.

The use of Spring Boot and Thymeleaf sounds good as a prerequisite, so I will introduce you to the official Spring Boot guide.
(You can check out the code from GitHub and move it as it is, so you can understand the atmosphere even if you don't understand the content right away.)

This is an implementation that limits input to the "Name" field of the input form to 2 to 30 characters or less, and if this condition is not met, the error message "size must be between 2 and 30" will appear on the screen.

For detailed implementation instructions, search "validation" for Spring Boot Reference or Spring MVC Reference.

Anyway, I think it would be easier to get a more specific answer if you could add something like this to the questionnaire, such as whether the direction of the question is like this or not, but (for example) I want to make it happen at the front desk/JavaScript.


2022-09-30 18:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.