HTML Forms and Validation events

Source: Internet
Author: User

1. Form Verification <form></form>

(1) Non-null verification (go blank)

(2) comparison verification (compared with a value)

(3) Scope validation (judging by a range)

(4) Fixed format verification: Telephone number, ID card number, mailbox, credit card number, etc., need to use regular expression to verify.

(5). Other validation

2. Regular expressions

Use symbols to describe writing rules:/ Middle Write Regular expression/

^: match at the beginning, $: match end;/^ve/with ve beginning/ve$/with VE end

\d: An arbitrary number

\w: An arbitrary number or letter

\s:

{n}: Repeat n-times the expression on the left

{M,n}: Repeat the expression on the left at least m times, up to N times
{m,}: Repeat at least M-times the expression on the left, at most

+: The expression on the left appears at least once, at most, equal to {1,}

*: The expression on the left appears at least 0 times, at most, equal to {0}

?: the expression on the left appears at least 0 times and appears at most 1 times, equivalent to {0,1}

[A,b,c]: Only one of the contents in square brackets can be taken

[A-z] or [1-9]: Take one of the ranges

|: delegate or; (): priority; \: Escaped--"\ (\)" This is the parenthesis that will appear, need to be escaped

3. Events

Events have three elements: event source, event data, event handler

Event bubbling: When an element is nested, an event is fired by the inner element, and the corresponding event of the external element is then triggered by default.

can add return false;

OnClick: mouse click Trigger

OnDblClick: Double-click Trigger

onMouseOver: Mouse movement above trigger

onMouseOut: Triggers when the mouse leaves

OnMouseMove: Triggers when the mouse moves above

onchange: Whenever content changes trigger

Onblur: triggers when losing focus

Onfocus: Triggers when focus is acquired

OnKeyDown: Trigger when button is pressed

OnKeyUp: Trigger When the button is lifted up

onkeypress: event occurs when the user presses and releases any alphanumeric keys. However, the system buttons (for example: arrow keys, function keys) cannot be identified.

Example: Verifying mailboxes based on regular expressions

123456789101112131415 function checkemail()  {       var v4 = trim(u4.value);       var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;       if(v4.match(reg) != null)       {               imgs4.setAttribute("src","imges/1.png");               return true;       }       else       {              imgs4.setAttribute("src","imges/2.png");               return false;       }}       

HTML Forms and Validation events

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.