In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to achieve layui regular expression verification", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to implement layui regular expression validation.
Preface
The regular expression of layui is done in the form form. So the first step is to add the specified form to your html.
Make sure that form.js exists in the referenced layui module.
The quick step refers to form.js to add the form tag, and sets the class attribute to layui-form. You cannot add lay-verify to the attribute to be verified to declare layui.form and listen for submitted button events. Quote js
The main purpose is to ensure the existence of form.js in lay.modules.
You can also quote form.js directly.
Add form tags
Set the properties to validate
Assign a value to lay-verify
The following attributes are included with the system:
Required (required)
Phone (mobile phone number)
Email (mailbox)
Url (website)
Number (digital)
Date (date)
Identity (ID card)
Custom value
If you don't have what you want, you can write it yourself, such as
Custom validation
Attributes validated by html tags
Custom rules for validation
Form.verify ({username: function (value, item) {/ / value: the value of the form, item: the form's DOM object if (! new RegExp ("^ [a-zA-Z0-9 _\ u4e00 -\ u9fa5\\ s] + $") .test (value)) {return 'username cannot have special characters' } if (/ (^\ _) | (\ _ + $) / .test (value)) {return 'usernames cannot be underlined\' _\';} if (/ ^\ d+\ d+\ d$/.test (value)) {return 'usernames cannot be all numeric' }} / / We support both the above functions and the two values of the following array: [regular matching, prompt text in case of mismatch], pass: [/ ^ [\ S] {6pr 12} $/, 'password must be 6 to 12 digits, and no spaces can appear]})
Instructions for using layui-form
1. You must render before select can be used.
Layui.use ('form', function () {var form = layui.form; / / only by performing this step will some form elements be automatically decorated successfully / /... / / however, if your HTML is dynamically generated, automatic rendering will fail / / so you need to perform the following methods to render form.render ();} in the appropriate place
Submit button
Confirm to place the order
Js custom js for verification and actions on submission
Layui.use ('form', function () {var form = layui.form; form.render (); form.verify ({payTotalAmount: [/ (^ [1-9]\ d (\.\ d {1Magne2})? $) | (^ 0 (\.\ d {1Magazine 2})? $) /,' Please enter the appropriate price']}); form.on ("submit (submit_button)", function () {onclickSearch ();}) At this point, I believe you have a deeper understanding of "how to implement layui regular expression validation". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.