Tuesday 15 May 2012

javascript - Validate a text input field for inline styles using regex? -



javascript - Validate a text input field for inline styles using regex? -

i have simple text field need validate regex. text field supposed contain inline-styles in "proper" format xxx: xxx;

ex: font-size: 15px; background: #33333; -webkit-transition: background-color 500ms ease-out 1s;

any regex gurus out there help me out here. i'll find solution on own may take awhile.

languages javascript client side validation moving onto php server side validation.

thanks bunch guys... came -- /([a-z-]+: [0-9a-z#(). -]+;$)/g --. reply myself i'm unsure if best solution.

gonna take detailed reply below @nu11p01n73r stole $ sign explanation made above work right.

now there issue came with? know i'm not technically supposed inquire think easier read me read, anyways. love so.

you can utilize regex of form

^([^:]+:[^;]+;)+$

see illustration http://regex101.com/r/ce6ys6/3

^ anchors regex @ begining of string. ensures nil presceds matched string

[^:]+: matches other : followed :

[^;]+; matches other ; followed ;

+ quantifier, repeats occurence of property:value;

$ anchors regex @ end of string. ensures nil follows matches string.

javascript php css regex

No comments:

Post a Comment