<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: validate code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 00:47:27 GMT</pubDate>
    <description>DZone Snippets: validate code</description>
    <item>
      <title>Tidy with Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5120</link>
      <description>Ruby interface to HTML Tidy Library Project (tidy.sf.net).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  require 'tidy'&lt;br /&gt;  Tidy.path = '/usr/lib/libtidy.so'&lt;br /&gt;  html = '&lt;html&gt;&lt;title&gt;title&lt;/title&gt;Body&lt;/html&gt;'&lt;br /&gt;  xml = Tidy.open(:show_warnings=&gt;true) do |tidy|&lt;br /&gt;    tidy.options.output_xml = true&lt;br /&gt;    puts tidy.options.show_warnings&lt;br /&gt;    xml = tidy.clean(html)&lt;br /&gt;    puts tidy.errors&lt;br /&gt;    puts tidy.diagnostics&lt;br /&gt;    xml&lt;br /&gt;  end&lt;br /&gt;  puts xml&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;output&lt;br /&gt;&lt;code&gt;&lt;br /&gt;true&lt;br /&gt;line 1 column 1 - Warning: missing &lt;!DOCTYPE&gt; declaration&lt;br /&gt;line 1 column 7 - Warning: plain text isn't allowed in &lt;head&gt; elements&lt;br /&gt;Info: Document content looks like XHTML 1.0 Transitional&lt;br /&gt;2 warnings, 0 errors were found!&lt;br /&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;meta name="generator"&lt;br /&gt;content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org" /&gt;&lt;br /&gt;&lt;title&gt;title&lt;/title&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;body&gt;Body&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note: Couldn't get it to run on Ubuntu version 7.10 or 7.04 (LoadError: no such file to load -- tidy&lt;br /&gt;), however it ran fine on Gentoo.&lt;br /&gt;&lt;br /&gt;reference: http://tidy.rubyforge.org/&lt;br /&gt;&lt;br /&gt;*update 18-Mar-08 16:15*&lt;br /&gt;I got it working on Ubuntu I simply needed to add - require 'rubygems'</description>
      <pubDate>Fri, 08 Feb 2008 16:28:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5120</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>ValidateForm()</title>
      <link>http://snippets.dzone.com/posts/show/4286</link>
      <description>// ValidateForm()&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    Private Function ValidateForm() As FormValidity&lt;br /&gt;&lt;br /&gt;        Dim MyReturn As New FormValidity&lt;br /&gt;        Dim ReturnString As New StringBuilder&lt;br /&gt;        Dim IsValidForm As Boolean = True&lt;br /&gt;&lt;br /&gt;        If (txtFirstName.Text = "") Then&lt;br /&gt;            ReturnString.Append("First Name")&lt;br /&gt;            txtFirstName.Attributes.Add("style", "background-color:#EBECED")&lt;br /&gt;            txtFirstName.Focus()&lt;br /&gt;            IsValidForm = False&lt;br /&gt;        End If&lt;br /&gt;&lt;br /&gt;        If (txtLastName.Text = "") Then&lt;br /&gt;            ReturnString.Append(", Last Name")&lt;br /&gt;            txtLastName.Attributes.Add("style", "background-color:#EBECED")&lt;br /&gt;            If (IsValidForm) Then txtLastName.Focus()&lt;br /&gt;            IsValidForm = False&lt;br /&gt;        End If&lt;br /&gt;&lt;br /&gt;        Dim InputEmail As String = txtEmail.Text&lt;br /&gt;        Dim EmailExpression As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"&lt;br /&gt;        Dim Re As New Regex(EmailExpression)&lt;br /&gt;&lt;br /&gt;        If (Not Re.IsMatch(InputEmail)) Then&lt;br /&gt;            ReturnString.Append(", E-mail Address")&lt;br /&gt;            txtEmail.Attributes.Add("style", "background-color:#EBECED")&lt;br /&gt;            If (IsValidForm) Then txtEmail.Focus()&lt;br /&gt;            IsValidForm = False&lt;br /&gt;        End If&lt;br /&gt;&lt;br /&gt;        If (txtAdd1.Text = "") Then&lt;br /&gt;            ReturnString.Append(", Address 1")&lt;br /&gt;            txtAdd1.Attributes.Add("style", "background-color:#EBECED")&lt;br /&gt;            If (IsValidForm) Then txtAdd1.Focus()&lt;br /&gt;            IsValidForm = False&lt;br /&gt;        End If&lt;br /&gt;&lt;br /&gt;        If (txtCity.Text = "") Then&lt;br /&gt;            ReturnString.Append(", City")&lt;br /&gt;            txtCity.Attributes.Add("style", "background-color:#EBECED")&lt;br /&gt;            If (IsValidForm) Then txtCity.Focus()&lt;br /&gt;            IsValidForm = False&lt;br /&gt;        End If&lt;br /&gt;&lt;br /&gt;        If (ddlState.Text = "") Then&lt;br /&gt;            If (txtStateOther.Text = "") Then&lt;br /&gt;                ReturnString.Append(", State")&lt;br /&gt;                ddlState.Attributes.Add("style", "background-color:#EBECED")&lt;br /&gt;                If (IsValidForm) Then ddlState.Focus()&lt;br /&gt;                IsValidForm = False&lt;br /&gt;            End If&lt;br /&gt;        End If&lt;br /&gt;&lt;br /&gt;        If (txtZip.Text = "") Then&lt;br /&gt;            ReturnString.Append(", Zip")&lt;br /&gt;            txtZip.Attributes.Add("style", "background-color:#EBECED")&lt;br /&gt;            If (IsValidForm) Then txtZip.Focus()&lt;br /&gt;            IsValidForm = False&lt;br /&gt;        End If&lt;br /&gt;&lt;br /&gt;        If (ddlCountry.Text = "") Then&lt;br /&gt;            ReturnString.Append(", Country")&lt;br /&gt;            ddlCountry.Attributes.Add("style", "background-color:#EBECED")&lt;br /&gt;            If (IsValidForm) Then ddlCountry.Focus()&lt;br /&gt;            IsValidForm = False&lt;br /&gt;        End If&lt;br /&gt;&lt;br /&gt;        If (txtPhone.Text = "") Then&lt;br /&gt;            ReturnString.Append(", Phone")&lt;br /&gt;            txtPhone.Attributes.Add("style", "background-color:#EBECED")&lt;br /&gt;            If (IsValidForm) Then txtPhone.Focus()&lt;br /&gt;            IsValidForm = False&lt;br /&gt;        End If&lt;br /&gt;&lt;br /&gt;        MyReturn.IsValid = IsValidForm&lt;br /&gt;&lt;br /&gt;        If (ReturnString.ToString.StartsWith(",")) Then&lt;br /&gt;            MyReturn.FormFields = ReturnString.ToString.Substring(1)&lt;br /&gt;        Else&lt;br /&gt;            MyReturn.FormFields = ReturnString.ToString&lt;br /&gt;        End If&lt;br /&gt;&lt;br /&gt;        Return MyReturn&lt;br /&gt;&lt;br /&gt;    End Function&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 11 Jul 2007 19:39:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4286</guid>
      <author>uadeeb (Umar)</author>
    </item>
    <item>
      <title>Validate email and domain</title>
      <link>http://snippets.dzone.com/posts/show/4022</link>
      <description>// Vlidate email and domain name&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;function validate_email($email){&lt;br /&gt;&lt;br /&gt;$exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";&lt;br /&gt;&lt;br /&gt;if(eregi($exp,$email)){&lt;br /&gt;	if(checkdnsrr(array_pop(explode("@",$email)),"MX")){&lt;br /&gt;		print("$email is ok.&lt;br&gt;");&lt;br /&gt;			}else{&lt;br /&gt;			print("$email is ok. But domain is not.&lt;br&gt;");&lt;br /&gt;			}&lt;br /&gt;				}else{&lt;br /&gt;				print("$email is not ok.&lt;br&gt;");&lt;br /&gt;				}   &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;validate_email("shantanu.ok");&lt;br /&gt;validate_email("shantanu.ok@gmail.com");&lt;br /&gt;validate_email("shantanu.ok@fsjaldkfjlsfjsljflsfjsldk.com");&lt;br /&gt;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 15 May 2007 07:48:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4022</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
  </channel>
</rss>
