Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a idea of creating java script validation framework using class or using custom html attrbutes.

Eg:
HTML
<input type='text' name='txtUserName' class='txtBoxNormal req alphaOnly minLen:5 maxlen:12'>


txtBoxNormal => for applying css style
req => to speacify required field
alphaOnly => to specify alphabetic only allowed
minLen:5 & maxlen:12 => to restrict length of text allowed

Or shall i use below idea:

Eg:
HTML
<input type='text' name='txtUserName' required='true' type='alphOnly' minlen='5' maxlen='12'>


Can i know which will be flexible and efficient idea? pls guide me

[Edit]Code block added[/Edit]
Posted
Updated 22-Oct-12 7:23am
v2

1 solution

In principle, you can retrieve a value of any attribute using getAttribute function:
http://www.w3schools.com/jsref/met_element_getattribute.asp[^].

I would say this practice is questionable. I would not recommend it. Even though it should practically work, such HTML usage cannot be standard. If you process HTML as XHTML (which is very reasonable, because it helps to eliminate non-well-formed constructs and perform tighter testing in general), your HTML will fail. This is explainable. What if the future HTML standard introduces some new attributes with the same name as yours? Where will you be in this case?

—SA
 
Share this answer
 
Comments
HarisJayadev 22-Oct-12 14:26pm    
what about using class name ?
Sergey Alexandrovich Kryukov 22-Oct-12 14:59pm    
Same thing, only this is standard, so it's safe to use. As to the getAttribute usage -- attribute is attribute.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900