Thursday, August 28, 2008

Common Phone validator RegEx , E-mail validator Regular Expression

I use custom validators to validate my forms email and phone numbers.
In most of the public website that I developed I use this two common javascript functions to work with ASP.NET validators.






<asp:textbox id="txtPhoneNumber" maxlength="13" runat="server"></asp:textbox>

<asp:customvalidator id="valPhone" runat="server" cssclass="ErrorLabel" errormessage="* required" clientvalidationfunction="validatePhone" controltovalidate="txtPhoneNumber" validateemptytext="true"></asp:customvalidator>

function validatePhone(sender, args)
{
if(args.Value.length > 0)
{
var ex = /\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
var re = new RegExp(ex);

if(re.exec(args.Value))
{
args.IsValid = true;
}
else
{
sender.errormessage= "* invalid";
sender.innerHTML= sender.errormessage;
args.IsValid = false;
}
}
else
{
sender.errormessage= "* required";
sender.innerHTML= sender.errormessage;
args.IsValid = false;
}
}

function validateEmail(sender, args)
{
if(args.Value.length > 0)
{
var ex = /^([a-zA-Z0-9_.+-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
var re = new RegExp(ex );

if(re.exec(args.Value))
{
args.IsValid = true;
}
else
{
sender.errormessage= "* invalid";
sender.innerHTML= sender.errormessage;
args.IsValid = false;
}
}
else
{
sender.errormessage= "* required";
sender.innerHTML= sender.errormessage;
args.IsValid = false;
}
}


How to override .NET validator error message font color

I hate the red color in the asp.net validators using the inline style attribute.

If you create a css class defining your color will do no good since the inline style will override your set color.

Instead of setting the FontColor Property in every single control, create a css class with the following code:

.error {
color:#e95e31 !important;
}

This will look like this My Error Message!

Monday, August 25, 2008

Error starting rails WEBRick server - ActionController::Caching::Fragments::MemCacheStore (NameError)

I go into error when trying to update my gems this week. After an unsuccessful gem update I found my self with the following error when trying to run my WEBRick server.


c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:263:in `load_missing_constant': uninitialized constant

ActionController::Caching::Fragments::MemCacheStore (NameError)


I checked to see if my memcached-client was installed and it was there. I compared with another developer and the same files were there. After unsuccessful debugging I took the choice to uninstall the entire ruby language and also rails framework.

I follow this tutorial http://tubecaption.com/watch?v=c0jR_hptpdA that demonstrate the order of how to uninstall / remove your gems.

Wednesday, August 20, 2008

Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its depend

I deployed a site that was using the AjaxToolKit and had references to the System.Web.Extensions.

I found this error Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its depend

This is due that it could not find that assembly System.Web.Extensions or System.Web.Extensions.Design in the bin or the GAC folder C:\Windows\assembly.

I solved this error my installing the ASP.NET AJAX 1.0 package from Microsoft.
You can download it at http://www.microsoft.com/downloads/details.aspx?FamilyID=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6&displaylang=en


This msi installs in your GAC (C:\Windows\assembly) the correct assemblies System.Web.Extensions version 1.0.61025.0