I added a new function to the toolbox to validate a password field specifically, assuming that the password may have upper/lower case letters, numbers, or any one of a few punctuations (see actual code for reference). I'm posting about this because I added it to the ValidateAlpha class.As I did so I thought that really the Alpha is not the most accurate name as there are functions in there that validate strings beyond just alpha. However it's kind of late to rename it since it's widely called.
Just be aware that these kinds of functions may already exist before troubling yourself writing a new one!
Showing posts with label DCToolbox. Show all posts
Showing posts with label DCToolbox. Show all posts
Monday, June 29, 2009
Wednesday, July 9, 2008
Remove Whitespace
I added this method to the StringManip class in DCToolbox:
protected string RemoveWhiteSpace(string str)
{
if (str.Length > 0)
{
while (str.IndexOf(" ") > 0)
{
str = Regex.Replace(str, " ", "");
}
}
str = str.Trim();
return str;
}
Tuesday, July 8, 2008
validators in DCToolBox
I copied into DCToolBox a bunch of the validators that Jinghua has written. The idea is that client side validation will be run first but in a client with Javascript disabled, these server side validators will run instead. I modified a few of them, which were for optional fields, to take an optional T/F parameter. Eventually all of the validators should have this, then they can be used for both required or optional fields.
I also added some new ones, including this:
This is for those situations where at least one of several fields must be answered - for example if you have 4 phone number fields, at least one of them must be filled in. Check all of them, returning a bool indicating if they are answered, and then collect those bools into a List<> and send that list to this function.
I have also written a few functions for returning a simple t/f to indicate whether a field has an answer to work with the above function.
Questions? Comments? Let 'er rip! If you need an example of how to use these validators in a project then let us know and one of us can post it.
I also added some new ones, including this:
public static bool AtLeastOne(ListlistOfResults, string msg, CustomValidator validator)
{
bool bOK = false;
foreach (bool i in listOfResults){
if (i == true)
{
bOK = true;
break;
}
}
//check only if no true items - meaning no field was answered
if (!bOK)
{
validator.ErrorMessage += String.Format(msg);
bOK = false;
}
return bOK;
}
This is for those situations where at least one of several fields must be answered - for example if you have 4 phone number fields, at least one of them must be filled in. Check all of them, returning a bool indicating if they are answered, and then collect those bools into a List<> and send that list to this function.
I have also written a few functions for returning a simple t/f to indicate whether a field has an answer to work with the above function.
Questions? Comments? Let 'er rip! If you need an example of how to use these validators in a project then let us know and one of us can post it.
Subscribe to:
Posts (Atom)