This article mainly introduces simple examples of form verification using HTML5, including a small example of using mobile phones. Friends who need it can refer to it.
HTML5 provides a paste attribute for form elements, which accepts a regular expression. This regular expression will be used to verify the non-empty value in the form when submitting the form. If the value of the control does not match the regular expression, a prompt box will pop up and prevent the expression from submitting. The text in the prompt box can be customized using the setCustomValidity method.
For example, in the form below, the text box only accepts mobile phone numbers from mainland China, and if you enter other things, you cannot submit it.
run
XML/HTML Code Copy content to clipboard