Regular Expressions used to determine whether a color is valid (detailed description)

Source: Internet
Author: User

Regular Expressions used to determine whether a color is valid (detailed description)

"^ # ([0-9a-fA-F] {6} | [0-9a-fA-F] {3}) $ ";

It indicates that it starts with # and is followed by a number and a-f characters (in upper or lower case). The value is 6 or 3 characters. Match a 3 to conform to the abbreviated css color rules:

"# Abc" = "# aabbcc"

Note: If you need to convert 16-bit and 10-bit values, for example, to convert the color value to int, there is a database. If it is a 6-bit color, there is no problem, if it is a 3-digit color, it will be wrong, because when you get it back, it will be converted from 10 hexadecimal

In hexadecimal notation, you don't know whether it should be three or six digits.

For example: # convert FF = to 10 hexadecimal => 255. If it is transferred back: 255 = to hexadecimal => ff, if you know it is 6 digits, you can add "#0000" to it and change it to "# 0000ff ", if it is three digits, it becomes "# 0ff"

Therefore, if you want to convert to a 10-digit storage, the three-digit color value should not exist, alternatively, convert the color value to a six-digit color value before saving it.

The above regular expression used to determine whether the color is valid (detailed description) is all the content shared by the editor. I hope you can give us a reference and support for the customer's house.

Related Article

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.