Custom HTML Validation Rules

For technical support for all editions of CSE HTML Validator. Includes bug reports.

Custom HTML Validation Rules

Postby Anjana P » Thu Sep 22, 2011 11:47 pm

Hi,

I am using CSE HTML Validator Pro v10.02. I would like know how to create custom HTML validation rules for our standard coding pattern. I would like to throw user an error when he violates our coding pattern. Below are some examples which will explain my requirement better:

1. Cannot nest <div class="XYZ"> under <div class="ABC"> -- on a page which user masterPage="ABC"
2. Cannot nest <div class="XYZ"> under <div class="ABC"> -- irrespective master page.
3. Cannot nest <input> under <div class="ABC">

Thanks in Advance :)!

-Anjana P
Anjana P
Rank I - Novice
Rank I - Novice
 
Posts: 18
Joined: Thu Sep 22, 2011 11:24 pm

Re: Custom HTML Validation Rules

Postby Albert Wiersch » Sat Sep 24, 2011 9:39 am

Hello,

CSE HTML Validator Pro+ v11 will allow a "user functions" file that makes it easier to configure CSE HTML Validator and keep the configuration through updates.

I don't think it will be too difficult to do what you want. In the user functions file, which is just a text file with functions, you could do something like this:

Code: Select all
function onStartValidation() {
 #indivcount=0;
 $divclassarray='';
}

function onStartTag_div() {
 #indivcount++;
// Message(1,MSG_MESSAGE,'<div> level '+$indivcount+'.'); // for testing
 if hasAtt("class") {
  #classindex=getAttIndex("class");
  $classvalue=getAttValue(#classindex);
//  Message(1,MSG_MESSAGE,'<div class="'+$classvalue+'">.'); // for testing
  if matchNoCase($classvalue,"XYZ") {
   if isValueInArray("divclassarray","ABC")>=0 {
    Message(1,MSG_ERROR,'Cannot nest <div class="'+$classvalue+'"> under <div class="ABC">.');
   }
  }
  $divclassarray[#indivcount]=$classvalue;
 }
}

function onEndTag_div() {
 $divclassarray[#indivcount]='';
 #indivcount--;
}

function onStartTag_input() {
 if isValueInArray("divclassarray","ABC")>=0 {
  Message(1,MSG_ERROR,'Cannot nest <input> under <div class="ABC">.');
 }
}


Save the above code in a file like "MyUserFunctions.cfg" and specify it in the Validator Engine Options->Validator Engine->Config File tab.

I gave the above a brief test and it seems to work well.

You will be able to do this in the upcoming v11 PUBLIC BETA, which I expect to release in about two weeks or so. If you'd like to try this sooner, I can send you a test build. Let me know!
Image
Albert Wiersch
User avatar
Albert Wiersch
Site Admin
Site Admin
 
Posts: 2361
Joined: Sat Dec 11, 2004 10:23 am
Location: Near Dallas, TX

Re: Custom HTML Validation Rules

Postby Anjana P » Mon Sep 26, 2011 7:36 am

Wow. Great! Thanks :)!!

Yes, please send me your test build on my email ID. Can't wait to try it out :)

-Anjana P
Anjana P
Rank I - Novice
Rank I - Novice
 
Posts: 18
Joined: Thu Sep 22, 2011 11:24 pm

Re: Custom HTML Validation Rules

Postby Albert Wiersch » Mon Sep 26, 2011 8:04 am

Anjana P wrote:Wow. Great! Thanks :)!!

Yes, please send me your test build on my email ID. Can't wait to try it out :)


Great! I just emailed you a download link. Please let me know how it works. The "user functions" is considered one of the new major features in V11 because it allows better & easier customization, so I appreciate any "real-use" feedback on it. Thanks!

PS. I deleted your post with your email address in it, to help protect you against spam.
Image
Albert Wiersch
User avatar
Albert Wiersch
Site Admin
Site Admin
 
Posts: 2361
Joined: Sat Dec 11, 2004 10:23 am
Location: Near Dallas, TX

Re: Custom HTML Validation Rules

Postby Anjana P » Tue Sep 27, 2011 8:11 am

Thanks a lot Albert!! I used your test build and changed the function a bit to match our coding pattern and it worked like a charm. Although I must say I will need to understand how to create those functions well :D.

Looking forward to the official release of v11 :).

-Anjana P
Anjana P
Rank I - Novice
Rank I - Novice
 
Posts: 18
Joined: Thu Sep 22, 2011 11:24 pm

Re: Custom HTML Validation Rules

Postby Anjana P » Tue Sep 27, 2011 8:11 am

Oh and thanks for removing my email ID from the post .. very thoughtful of you :).

-Anjana P
Anjana P
Rank I - Novice
Rank I - Novice
 
Posts: 18
Joined: Thu Sep 22, 2011 11:24 pm

Re: Custom HTML Validation Rules

Postby Albert Wiersch » Tue Sep 27, 2011 8:41 am

Anjana P wrote:Thanks a lot Albert!! I used your test build and changed the function a bit to match our coding pattern and it worked like a charm. Although I must say I will need to understand how to create those functions well :D.


Great! I'm glad it worked.

Anjana P wrote:Looking forward to the official release of v11 :).


Me too. :D
Image
Albert Wiersch
User avatar
Albert Wiersch
Site Admin
Site Admin
 
Posts: 2361
Joined: Sat Dec 11, 2004 10:23 am
Location: Near Dallas, TX


Return to CSE Tech Support

Who is online

Users browsing this forum: No registered users and 1 guest