Click here to Skip to main content
15,887,393 members
Articles / Programming Languages / Visual Basic
Article

TextBox whith Validation Functions and MaskEdit

Rate me:
Please Sign up or sign in to vote.
4.61/5 (35 votes)
30 May 20032 min read 210.9K   1.3K   54   18
Custom control that inherits from TextBox class and adds input validation functions, required validation functions and MaskEdit.

Sample screenshot

Introduction

This is my first custom control, which I decided to do, to learn about this topic and to make it easy to work with forms validation data. This control inherits all attributes and methods from the TextBox class and adds some input and required validations. The validation options are:

  • None.
  • Valid chars validation.
  • Invalid chars validation.
  • Letters validation.
  • Numbers validation.
  • MaskEdit.
  • Regular expression validation (E-mail, IP, URL, ZIP, Fecha and Custom).

Using the code

ValidText as any other .NET component, can be added to the IDE ToolBox to be put graphically into Windows forms and modify their properties from the properties window in the Validation Category. It can also be used like reference, using its methods and modifying its attributes directly from the code, after generating an instance of its class.

Properties

  • ValitationMode (ValidationTypes): Sets the validation mode to use for the text or data field. This validation mode can be: None, VaidChars, InvalidChars, Letters, Numbers, MaskEdit and RegEX.
  • MaskString (String): Sets the allowed mask for the input data when ValidationMode = MaskEdit. Character # suggests a digit, A suggests upper letter, z suggests lower letter, $ suggests an upper letter, lower letter, or number. Any other character will be seen as a fixed character in the mask. For example: If the ValidationMode property = MaskEdit and MaskString = ###- (AAA) - ##/aa/AA/&&/$$$, user can be able to write data of 345 - ( ABC ) - 22/ad/CD/Ad/s3G types in the text control.
  • ValidString (String): Sets the valid and not valid characters allowed when ValidationMode = ValidChars, InvalidChars or RegEx.
  • ShowErrorIcon (Boolean): Sets if the icon and tool tip of the ErrorProvider is shown in the validation of the data field.
  • Required (Boolean): Sets if the data field must have at last one character to be validated.
  • Reference (String): Sets the link between the text control and the data field to get. This property is used to make the validation error messages.
  • RegExMode (RegExTypes): Sets the regular expression mode to use for the text or data field. This regular expression mode can be: Custom, Email, URL, IP, Date or ZIP.
  • MessageLanguage (MessageLanguages) : Sets error icon messages language. (English, Español)

Methods

  • requiredFieldsCheck: This share method of the ValidText class returns true if the form you send as parameter has at last one ValidText control with Required property = TRUE and Text property = “”
    VB
    Private Sub btnAceptar_Click(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) Handles btnAceptar.Click
        If ValidText.ValidText.requiredFieldsCheck(Me) = True Then
            MsgBox("OK!", MsgBoxStyle.Information, Me.Text)
            Me.Close()
        Else
            MsgBox("There are required fiels in the form!", _
                          MsgBoxStyle.Exclamation, Me.Text)
        End If
    End Sub
  • cancelRequiredFieldsCheck: Lets avoid the required validation of ValidText controls of the form you send as parameter.
    VB
    Private Sub btnCancelar_Click(ByVal sender As System.Object,_
                  ByVal e As System.EventArgs) Handles btnCancelar.Click
    ValidText.ValidText.cancelrequiredFieldsCheck(Me)
    Me.Close()
    End Sub

Note: The buttons or others control used to fire these methods need to set their Causesvalidation property to FALSE, in order to have access to their events.

Conclusion

Please send me feedback, comments, and suggest to: ra_luis@yahoo.com

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Costa Rica Costa Rica
Ing. Luis Alberto Ruiz Arauz
Software Engineering / Industrial Engineering

Comments and Discussions

 
QuestionCan I use this DLL with VB6? Pin
lemorlenny23-Feb-09 22:03
lemorlenny23-Feb-09 22:03 
Questionwhat is use of mask field ??? pls say how to use the code Pin
rama charan24-Nov-06 6:01
rama charan24-Nov-06 6:01 
Generalbig thanks Pin
DaveMon13-Apr-06 11:09
DaveMon13-Apr-06 11:09 
GeneralC# version Pin
yamabiz15-Feb-06 11:20
yamabiz15-Feb-06 11:20 
namespace ValidText
{
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Windows.Forms;

[ToolboxBitmap(typeof(ValidText.ValidText), "ValidText.ico")]
public class ValidText : TextBox
{

[AccessedThroughProperty("erpShowError")]
private ErrorProvider _erpShowError;
[AccessedThroughProperty("erpShowRequired")]
private ErrorProvider _erpShowRequired;
[AccessedThroughProperty("miForm")]
private Form _miForm;
private IContainer components;
private string DATEC;
private string EMAIL;
public bool ErrorTrapped;
private bool firstLoad;
private bool firstTime;
private string IP;
private byte isRequired;
private string keyType;
private string lastText;
private string LETTERS;
private string m_FieldReference;
private string m_MaskEdit;
private MessageLanguages m_MessageLanguage;
private RegularExpressionModes m_RegExPattern;
private bool m_Required;
private bool m_ShowErrorIcon;
private ValidationModes m_ValidationMode;
private string m_ValidText;
private bool maskBool;
private string maskString;
private string maskText;
private string maskValues;
private string NUMBERS;
private bool secondLoad;
private bool thirdLoad;
private string URL;
private bool validCharBool;
private bool vexit;
private string ZIP;


public enum MessageLanguages
{
English,
Español
}

public enum RegularExpressionModes
{
Custom,
Email,
Url,
IP,
Dates,
Zip
}

public enum ValidationModes
{
None,
ValidCharacters,
InvalidCharacters,
Letters,
Numbers,
MaskEdit,
RegularExpression
}

public ValidText()
{
base.TextChanged += new EventHandler(this.eventTextChanged_validText);
base.KeyPress += new KeyPressEventHandler(this.eventKeyPress_validText);
base.Validating += new CancelEventHandler(this.eventValidating_validText);
base.Validated += new EventHandler(this.eventValidated_validText);
base.Enter += new EventHandler(this.eventoEnter_validText);
base.Leave += new EventHandler(this.eventoLeave_validText);
this.firstTime = true;
this.firstLoad = true;
this.secondLoad = false;
this.thirdLoad = false;
this.lastText = "";
this.maskBool = false;
this.validCharBool = false;
this.isRequired = 0;
this.vexit = false;
this.miForm = base.FindForm();
this.LETTERS = "A\x00c1BCDE\x00c9FGHI\x00cdJKLMN\x00d1O\x00d3PQRSTU\x00da\x00dcVWXYZ";
this.NUMBERS = "1234567890";
this.EMAIL = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
this.IP = @"(?<first>[01]?\d\d?|2[0-4]\d|25[0-5])\.(?<second>[01]?\d\d?|2[0-4]\d|25[0-5])\.(?<third>[01]?\d\d?|2[0-4]\d|25[0-5])\.(?<fourth>[01]?\d\d?|2[0-4]\d|25[0-5])(?x) ";
this.URL = @"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/";
this.DATEC = @"(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>(?:\d{4}|\d{2}))(?x)";
this.ZIP = @"(?<zip>\d{5})-(?\d{4})(?x)";
this.ErrorTrapped = false;
this.InitializeComponent();
}

public static void cancelrequiredFieldsCheck(Form pForm)
{
int num8 = pForm.Controls.Count - 1;
for (int num1 = 0; num1 <= num8; num1++)
{
if (StringType.StrCmp(pForm.Controls[num1].GetType().ToString(), "ValidText.ValidText", false) == 0)
{
((ValidText.ValidText) pForm.Controls[num1]).isRequired = 1;
((ValidText.ValidText) pForm.Controls[num1]).erpShowError.SetError((ValidText.ValidText) pForm.Controls[num1], "");
((ValidText.ValidText) pForm.Controls[num1]).erpShowRequired.SetError((ValidText.ValidText) pForm.Controls[num1], "");
}
int num7 = pForm.Controls[num1].Controls.Count - 1;
for (int num2 = 0; num2 <= num7; num2++)
{
if (StringType.StrCmp(pForm.Controls[num1].Controls[num2].GetType().ToString(), "ValidText.ValidText", false) == 0)
{
((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).isRequired = 1;
((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).erpShowError.SetError((ValidText.ValidText) pForm.Controls[num1].Controls[num2], "");
((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).erpShowRequired.SetError((ValidText.ValidText) pForm.Controls[num1].Controls[num2], "");
}
int num6 = pForm.Controls[num1].Controls[num2].Controls.Count - 1;
for (int num3 = 0; num3 <= num6; num3++)
{
if (StringType.StrCmp(pForm.Controls[num1].Controls[num2].Controls[num3].GetType().ToString(), "ValidText.ValidText", false) == 0)
{
((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).isRequired = 1;
((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).erpShowError.SetError((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3], "");
((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).erpShowRequired.SetError((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3], "");
}
int num5 = pForm.Controls[num1].Controls[num2].Controls[num3].Controls.Count - 1;
for (int num4 = 0; num4 <= num5; num4++)
{
if (StringType.StrCmp(pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4].GetType().ToString(), "ValidText.ValidText", false) == 0)
{
((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).isRequired = 1;
((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).erpShowError.SetError((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4], "");
((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).erpShowRequired.SetError((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4], "");
}
}
}
}
}
}

protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}

public void eventKeyPress_validText(object sender, KeyPressEventArgs e)
{
char ch1 = e.KeyChar;
if (ch1 == '\b')
{
this.keyType = "BackSP";
}
else
{
this.keyType = "Other";
}
if ((this.m_ValidationMode == ValidationModes.MaskEdit) && (StringType.StrCmp(this.Text, "", false) == 0))
{
this.Text = this.m_MaskEdit;
}
}

private void eventLoad_ValidTextForm(object sender, EventArgs e)
{
if (this.isRequired == 1)
{
this.isRequired = 0;
}
}

public void eventoEnter_validText(object sender, EventArgs e)
{
int num2 = this.Text.Length - 1;
int num1 = 0;
while (num1 <= num2)
{
if (StringType.StrCmp(StringType.FromChar(this.Text[num1]), "_", false) == 0)
{
break;
}
num1++;
}
this.SelectionStart = num1;
}

private void eventoLeave_validText(object sender, EventArgs e)
{
string text1;
string text2;
if (StringType.StrCmp(this.Text, "", false) == 0)
{
this.erpShowError.SetError(this, "");
this.ErrorTrapped = true;
goto Label_01F1;
}
if (this.m_ValidationMode != ValidationModes.RegularExpression)
{
this.erpShowError.SetError(this, "");
this.ErrorTrapped = true;
goto Label_01F1;
}
switch (this.m_RegExPattern)
{
case RegularExpressionModes.Custom:
{
if (StringType.StrCmp(this.m_ValidText, "", false) == 0)
{
return;
}
text1 = this.m_ValidText;
break;
}
case RegularExpressionModes.Email:
{
text1 = this.EMAIL;
text2 = "Email";
break;
}
case RegularExpressionModes.Url:
{
text1 = this.URL;
text2 = "URL";
break;
}
case RegularExpressionModes.IP:
{
text1 = this.IP;
text2 = "IP";
break;
}
case RegularExpressionModes.Dates:
{
text1 = this.DATEC;
switch (this.m_MessageLanguage)
{
case MessageLanguages.English:
{
text2 = "Date";
break;
}
case MessageLanguages.Español:
{
text2 = "DFecha";
break;
}
}
break;
}
case RegularExpressionModes.Zip:
{
text1 = this.ZIP;
text2 = "Zip code";
break;
}
}
if (Regex.IsMatch(this.Text, text1))
{
this.erpShowError.SetError(this, "");
this.ErrorTrapped = true;
goto Label_01F1;
}
switch (this.m_MessageLanguage)
{
case MessageLanguages.English:
{
if (this.m_RegExPattern != RegularExpressionModes.Custom)
{
this.erpShowError.SetError(this, "The entered value does not has\ra valid format for " + text2 + ".");
goto Label_0185;
}
this.erpShowError.SetError(this, "The entered value does not has\ra valid format for the field.");
goto Label_0185;
}
case MessageLanguages.Español:
{
if (this.m_RegExPattern != RegularExpressionModes.Custom)
{
this.erpShowError.SetError(this, "El valor ingresado no posee\run formato adecuado de " + text2 + ".");
break;
}
this.erpShowError.SetError(this, "El valor ingresado no posee\run formato adecuado para este campo.");
break;
}
default:
{
goto Label_0185;
}
}
Label_0185:
this.Select();
this.SelectAll();
this.ErrorTrapped = true;
Label_01F1:;
}

private void eventTextChanged_validText(object sender, EventArgs e)
{
int num1;
int num2;
if (this.vexit)
{
this.vexit = false;
return;
}
if (this.secondLoad)
{
this.lastText = this.Text;
this.secondLoad = false;
this.thirdLoad = true;
}
if (this.firstLoad)
{
this.secondLoad = true;
this.firstLoad = false;
}
this.erpShowRequired.SetError(this, "");
if (this.m_ValidationMode == ValidationModes.RegularExpression)
{
this.erpShowError.SetError(this, "");
}
bool flag1 = false;
bool flag2 = true;
Collection collection1 = new Collection();
switch (this.m_ValidationMode)
{
case ValidationModes.ValidCharacters:
{
if (!this.firstTime)
{
goto Label_0D40;
}
string text1 = this.m_ValidText;
flag1 = false;
if (StringType.StrCmp(this.Text, "", false) == 0)
{
this.erpShowError.SetError(this, "");
break;
}
this.firstTime = false;
string text2 = Strings.Mid(this.Text, this.Text.Length, 1);
int num25 = this.Text.Length - 1;
for (num1 = 0; num1 <= num25; num1++)
{
int num24 = text1.Length - 1;
num2 = 0;
while (num2 <= num24)
{
if (this.Text[num1] == text1[num2])
{
flag1 = true;
}
num2++;
}
if ((num2 == text1.Length) & !flag1)
{
flag2 = false;
collection1.Add(this.Text[num1], null, null, null);
}
flag1 = false;
}
if (!flag2)
{
if (this.m_ShowErrorIcon)
{
this.showError(collection1);
}
this.Text = this.lastText;
this.SelectionStart = this.Text.Length;
}
else
{
this.erpShowError.SetError(this, "");
}
this.firstTime = true;
break;
}
case ValidationModes.InvalidCharacters:
{
if (!this.firstTime)
{
goto Label_0D40;
}
string text3 = this.m_ValidText;
flag1 = false;
if (StringType.StrCmp(this.Text, "", false) == 0)
{
this.erpShowError.SetError(this, "");
goto Label_0329;
}
this.firstTime = false;
string text4 = Strings.Mid(this.Text, this.Text.Length, 1);
int num23 = this.Text.Length - 1;
for (num1 = 0; num1 <= num23; num1++)
{
int num22 = text3.Length - 1;
num2 = 0;
while (num2 <= num22)
{
if (this.Text[num1] == text3[num2])
{
flag1 = true;
}
num2++;
}
if ((num2 == text3.Length) & flag1)
{
flag2 = false;
collection1.Add(this.Text[num1], null, null, null);
}
flag1 = false;
}
if (!flag2)
{
if (this.m_ShowErrorIcon)
{
this.showError(collection1);
}
this.Text = this.lastText;
this.SelectionStart = this.Text.Length;
}
else
{
this.erpShowError.SetError(this, "");
}
this.firstTime = true;
goto Label_0329;
}
case ValidationModes.Letters:
{
if (!this.firstTime)
{
goto Label_0D40;
}
string text5 = "A\x00c1BCDE\x00c9FGHI\x00cdJKLMN\x00d1O\x00d3PQRSTU\x00da\x00dcVWXYZa\x00e1bcde\x00e9fghi\x00edjklmn\x00f1o\x00f3pqrstu\x00fa\x00fcvwxyz ,;.'";
flag1 = false;
if (StringType.StrCmp(this.Text, "", false) == 0)
{
this.erpShowError.SetError(this, "");
goto Label_046F;
}
this.firstTime = false;
string text6 = Strings.Mid(this.Text, this.Text.Length, 1);
int num21 = this.Text.Length - 1;
for (num1 = 0; num1 <= num21; num1++)
{
int num20 = text5.Length - 1;
num2 = 0;
while (num2 <= num20)
{
if (this.Text[num1] == text5[num2])
{
flag1 = true;
}
num2++;
}
if ((num2 == text5.Length) & !flag1)
{
flag2 = false;
collection1.Add(this.Text[num1], null, null, null);
}
flag1 = false;
}
if (!flag2)
{
if (this.m_ShowErrorIcon)
{
this.showError(collection1);
}
this.Text = this.lastText;
this.SelectionStart = this.Text.Length;
}
else
{
this.erpShowError.SetError(this, "");
}
this.firstTime = true;
goto Label_046F;
}
case ValidationModes.Numbers:
{
if (!this.firstTime)
{
goto Label_0D40;
}
string text7 = "1234567890.,";
flag1 = false;
if (StringType.StrCmp(this.Text, "", false) == 0)
{
this.erpShowError.SetError(this, "");
goto Label_05B5;
}
this.firstTime = false;
string text8 = Strings.Mid(this.Text, this.Text.Length, 1);
int num19 = this.Text.Length - 1;
for (num1 = 0; num1 <= num19; num1++)
{
int num18 = text7.Length - 1;
num2 = 0;
while (num2 <= num18)
{
if (this.Text[num1] == text7[num2])
{
flag1 = true;
}
num2++;
}
if ((num2 == text7.Length) & !flag1)
{
flag2 = false;
collection1.Add(this.Text[num1], null, null, null);
}
flag1 = false;
}
if (!flag2)
{
if (this.m_ShowErrorIcon)
{
this.showError(collection1);
}
this.Text = this.lastText;
this.SelectionStart = this.Text.Length;
}
else
{
this.erpShowError.SetError(this, "");
}
this.firstTime = true;
goto Label_05B5;
}
case ValidationModes.MaskEdit:
{
if (!this.maskBool)
{
if (this.firstTime)
{
this.Text = this.maskString;
this.maskText = this.maskString;
this.firstTime = false;
}
else if (StringType.StrCmp(this.Text, "", false) != 0)
{
int num3 = this.SelectionStart - 1;
string text16 = this.keyType;
if (StringType.StrCmp(text16, "BackSP", false) == 0)
{
string text11 = "";
string text10 = "";
int num5 = 0;
int num4 = 0;
int num17 = this.maskString.Length;
num1 = 0;
while (num1 <= num17)
{
if (num1 == (num3 + 1))
{
int num16 = (this.maskString.Length - this.Text.Length) - 1;
for (int num6 = 0; num6 <= num16; num6++)
{
text10 = text10 + "_";
num1++;
}
}
else
{
text10 = text10 + StringType.FromChar(this.Text[num5]);
num5++;
}
num1++;
}
num5 = 0;
int num15 = this.maskString.Length - 1;
for (num1 = 0; num1 <= num15; num1++)
{
if (text10[num5] == this.maskString[num1])
{
text11 = text11 + StringType.FromChar(this.maskString[num1]);
num5++;
num4++;
}
else if (text10[num5] == this.lastText[num4])
{
text11 = text11 + StringType.FromChar(this.lastText[num4]);
num5++;
num4++;
}
else
{
text11 = text11 + StringType.FromChar(this.maskString[num1]);
num5++;
num4++;
}
}
this.vexit = true;
this.keyType = "Nothing";
this.lastText = text11;
this.maskText = text11;
this.Text = text11;
this.SelectionStart = num3 + 1;
return;
}
if (StringType.StrCmp(text16, "Other", false) == 0)
{
if (num3 >= this.maskString.Length)
{
this.maskBool = true;
this.Text = this.maskText;
this.Select(num3 + 1, 0);
}
else
{
string text9 = StringType.FromChar(this.Text[num3]);
while ((StringType.StrCmp(StringType.FromChar(this.maskString[num3]), "_", false) != 0) & (num3 < (this.maskString.Length - 1)))
{
num3++;
}
if (((((StringType.StrCmp(StringType.FromChar(this.maskValues[num3]), "#", false) == 0) | (StringType.StrCmp(StringType.FromChar(this.maskValues[num3]), "A", false) == 0)) | (StringType.StrCmp(StringType.FromChar(this.maskValues[num3]), "a", false) == 0)) | (StringType.StrCmp(StringType.FromChar(this.maskValues[num3]), "&", false) == 0)) | (StringType.StrCmp(StringType.FromChar(this.maskValues[num3]), "$", false) == 0))
{
char ch1 = this.maskValues[num3];
if (ch1 == '#')
{
int num14 = this.NUMBERS.Length - 1;
for (num1 = 0; num1 <= num14; num1++)
{
if (StringType.StrCmp(text9, StringType.FromChar(this.NUMBERS[num1]), false) == 0)
{
this.validCharBool = true;
break;
}
}
}
else if (ch1 == 'A')
{
int num13 = this.LETTERS.Length - 1;
for (num1 = 0; num1 <= num13; num1++)
{
if (StringType.StrCmp(text9, StringType.FromChar(this.LETTERS[num1]), false) == 0)
{
this.validCharBool = true;
break;
}
}
}
else if (ch1 == 'a')
{
int num12 = this.LETTERS.Length - 1;
for (num1 = 0; num1 <= num12; num1++)
{
string text12 = StringType.FromChar(this.LETTERS[num1]);
if (StringType.StrCmp(text9, text12.ToLower(), false) == 0)
{
this.validCharBool = true;
break;
}
}
}
else if (ch1 == '&')
{
int num11 = this.LETTERS.Length - 1;
for (num1 = 0; num1 <= num11; num1++)
{
string text13 = StringType.FromChar(this.LETTERS[num1]);
if ((StringType.StrCmp(text9, text13.ToLower(), false) == 0) | (StringType.StrCmp(text9, StringType.FromChar(this.LETTERS[num1]), false) == 0))
{
this.validCharBool = true;
break;
}
}
}
else if (ch1 == '$')
{
int num10 = this.LETTERS.Length - 1;
num1 = 0;
while (num1 <= num10)
{
string text14 = StringType.FromChar(this.LETTERS[num1]);
if ((StringType.StrCmp(text9, text14.ToLower(), false) == 0) | (StringType.StrCmp(text9, StringType.FromChar(this.LETTERS[num1]), false) == 0))
{
this.validCharBool = true;
break;
}
num1++;
}
if (!this.validCharBool)
{
int num9 = this.NUMBERS.Length - 1;
for (num1 = 0; num1 <= num9; num1++)
{
if (StringType.StrCmp(text9, StringType.FromChar(this.NUMBERS[num1]), false) == 0)
{
this.validCharBool = true;
break;
}
}
}
}
if (this.validCharBool)
{
string text15 = "";
int num8 = this.maskString.Length - 1;
for (num1 = 0; num1 <= num8; num1++)
{
if (num1 == num3)
{
text15 = text15 + text9;
}
else
{
text15 = text15 + StringType.FromChar(this.maskText[num1]);
}
}
this.maskText = text15;
this.maskBool = true;
this.Text = this.maskText;
this.Select(num3 + 1, 0);
this.validCharBool = false;
}
else
{
this.maskBool = true;
this.Text = this.maskText;
this.Select(num3, 0);
}
}
else
{
this.maskBool = true;
this.Text = this.maskText;
this.Select(num3 + 1, 0);
}
}
}
else
{
this.lastText = this.Text;
if (StringType.StrCmp(this.keyType, "Nothing", false) == 0)
{
this.maskText = this.Text;
return;
}
this.maskBool = true;
this.Text = this.maskText;
if (num3 >= 0)
{
this.Select(num3 + 1, 0);
}
else
{
this.Select(0, 0);
}
}
this.keyType = "Nothing";
}
bool flag3 = true;
int num7 = this.Text.Length - 1;
for (num1 = 0; num1 <= num7; num1++)
{
if (StringType.StrCmp(StringType.FromChar(this.Text[num1]), "_", false) == 0)
{
flag3 = false;
}
}
if (flag3)
{
this.erpShowRequired.SetError(this, "");
}
if (StringType.StrCmp(this.Text, "", false) == 0)
{
this.ValidText_limpiaMaskEdit();
}
goto Label_0D40;
}
this.maskBool = false;
return;
}
default:
{
goto Label_0D40;
}
}
this.lastText = this.Text;
goto Label_0D40;
Label_0329:
this.lastText = this.Text;
goto Label_0D40;
Label_046F:
this.lastText = this.Text;
goto Label_0D40;
Label_05B5:
this.lastText = this.Text;
Label_0D40:
if (!this.thirdLoad)
{
this.lastText = this.Text;
}
else
{
this.thirdLoad = false;
}
}

public void eventValidated_validText(object sender, EventArgs e)
{
this.erpShowRequired.SetError(this, "");
}

public void eventValidating_validText(object sender, CancelEventArgs e)
{
if (!(this.m_Required & (this.isRequired == 0)))
{
return;
}
ValidationModes modes1 = this.m_ValidationMode;
if (modes1 != ValidationModes.MaskEdit)
{
if (StringType.StrCmp(this.Text, "", false) != 0)
{
goto Label_01A9;
}
e.Cancel = true;
if (!this.m_ShowErrorIcon)
{
goto Label_01A8;
}
this.erpShowError.SetError(this, "");
switch (this.m_MessageLanguage)
{
case MessageLanguages.English:
{
this.erpShowRequired.SetError(this, "Field " + this.m_FieldReference + " is required!");
goto Label_01A7;
}
case MessageLanguages.Español:
{
this.erpShowRequired.SetError(this, "El campo " + this.m_FieldReference + " es requerido!");
goto Label_01A7;
}
}
}
else
{
bool flag1 = false;
if (StringType.StrCmp(this.Text, "", false) != 0)
{
int num2 = this.maskString.Length - 1;
for (int num1 = 0; num1 <= num2; num1++)
{
if (StringType.StrCmp(StringType.FromChar(this.Text[num1]), "_", false) == 0)
{
flag1 = true;
break;
}
}
}
if (flag1)
{
e.Cancel = true;
if (this.m_ShowErrorIcon)
{
this.erpShowError.SetError(this, "");
switch (this.m_MessageLanguage)
{
case MessageLanguages.English:
{
this.erpShowRequired.SetError(this, "Field " + this.m_FieldReference + " is required!");
break;
}
case MessageLanguages.Español:
{
this.erpShowRequired.SetError(this, "El campo " + this.m_FieldReference + " es requerido!");
break;
}
}
}
}
goto Label_01AA;
}
Label_01A7:;
Label_01A8:;
Label_01A9:;
Label_01AA:;
}

private string[,] getMask(string p_Pattern)
{
string[,] textArray1 = new string[(p_Pattern.Length - 1) + 1, 2];
int num2 = p_Pattern.Length - 1;
for (int num1 = 0; num1 <= num2; num1++)
{
if (((((StringType.StrCmp(StringType.FromChar(p_Pattern[num1]), "#", false) == 0) | (StringType.StrCmp(StringType.FromChar(p_Pattern[num1]), "A", false) == 0)) | (StringType.StrCmp(StringType.FromChar(p_Pattern[num1]), "a", false) == 0)) | (StringType.StrCmp(StringType.FromChar(p_Pattern[num1]), "&", false) == 0)) | (StringType.StrCmp(StringType.FromChar(p_Pattern[num1]), "$", false) == 0))
{
char ch1 = p_Pattern[num1];
if (ch1 == '#')
{
textArray1[num1, 1] = "#";
}
else if (ch1 == 'A')
{
textArray1[num1, 1] = "A";
}
else if (ch1 == 'a')
{
textArray1[num1, 1] = "a";
}
else if (ch1 == '&')
{
textArray1[num1, 1] = "&";
}
else if (ch1 == '$')
{
textArray1[num1, 1] = "$";
}
textArray1[num1, 0] = "_";
}
else
{
textArray1[num1, 0] = StringType.FromChar(p_Pattern[num1]);
textArray1[num1, 1] = StringType.FromChar(p_Pattern[num1]);
}
}
return textArray1;
}

[DebuggerStepThrough]
private void InitializeComponent()
{
ResourceManager manager1 = new ResourceManager(typeof(ValidText.ValidText));
this.erpShowError = new ErrorProvider();
this.erpShowRequired = new ErrorProvider();
this.erpShowError.Icon = (Icon) manager1.GetObject("erpShowError.Icon");
}

private void muestraRequired()
{
this.erpShowError.SetError(this, "");
this.erpShowRequired.SetError(this, "Field " + this.m_FieldReference + " is Required!");
}

public static bool requiredFieldsCheck(Form pForm)
{
bool flag1 = false;
int num16 = pForm.Controls.Count - 1;
for (int num1 = 0; num1 <= num16; num1++)
{
if (StringType.StrCmp(pForm.Controls[num1].GetType().ToString(), "ValidText.ValidText", false) == 0)
{
if ((StringType.StrCmp(((ValidText.ValidText) pForm.Controls[num1]).Text, "", false) == 0) & ((ValidText.ValidText) pForm.Controls[num1]).Required)
{
((ValidText.ValidText) pForm.Controls[num1]).muestraRequired();
flag1 = true;
}
if (((((ValidText.ValidText) pForm.Controls[num1]).m_ValidationMode == ValidationModes.MaskEdit) & ((ValidText.ValidText) pForm.Controls[num1]).Required) && (StringType.StrCmp(((ValidText.ValidText) pForm.Controls[num1]).Text, "", false) != 0))
{
int num15 = ((ValidText.ValidText) pForm.Controls[num1]).Text.Length - 1;
for (int num5 = 0; num5 <= num15; num5++)
{
if (StringType.StrCmp(StringType.FromChar(((ValidText.ValidText) pForm.Controls[num1]).Text[num5]), "_", false) == 0)
{
((ValidText.ValidText) pForm.Controls[num1]).muestraRequired();
flag1 = true;
break;
}
}
}
}
int num14 = pForm.Controls[num1].Controls.Count - 1;
for (int num2 = 0; num2 <= num14; num2++)
{
if (StringType.StrCmp(pForm.Controls[num1].Controls[num2].GetType().ToString(), "ValidText.ValidText", false) == 0)
{
if ((StringType.StrCmp(((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).Text, "", false) == 0) & ((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).Required)
{
((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).muestraRequired();
flag1 = true;
}
if (((((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).m_ValidationMode == ValidationModes.MaskEdit) & ((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).Required) && (StringType.StrCmp(((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).Text, "", false) != 0))
{
int num13 = ((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).Text.Length - 1;
for (int num6 = 0; num6 <= num13; num6++)
{
if (StringType.StrCmp(StringType.FromChar(((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).Text[num6]), "_", false) == 0)
{
((ValidText.ValidText) pForm.Controls[num1].Controls[num2]).muestraRequired();
flag1 = true;
break;
}
}
}
}
int num12 = pForm.Controls[num1].Controls[num2].Controls.Count - 1;
for (int num3 = 0; num3 <= num12; num3++)
{
if (StringType.StrCmp(pForm.Controls[num1].Controls[num2].Controls[num3].GetType().ToString(), "ValidText.ValidText", false) == 0)
{
if ((StringType.StrCmp(((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).Text, "", false) == 0) & ((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).Required)
{
((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).muestraRequired();
flag1 = true;
}
if (((((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).m_ValidationMode == ValidationModes.MaskEdit) & ((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).Required) && (StringType.StrCmp(((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).Text, "", false) != 0))
{
int num11 = ((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).Text.Length - 1;
for (int num7 = 0; num7 <= num11; num7++)
{
if (StringType.StrCmp(StringType.FromChar(((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).Text[num7]), "_", false) == 0)
{
((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3]).muestraRequired();
flag1 = true;
break;
}
}
}
}
int num10 = pForm.Controls[num1].Controls[num2].Controls[num3].Controls.Count - 1;
for (int num4 = 0; num4 <= num10; num4++)
{
if (StringType.StrCmp(pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4].GetType().ToString(), "ValidText.ValidText", false) == 0)
{
if ((StringType.StrCmp(((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).Text, "", false) == 0) & ((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).Required)
{
((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).muestraRequired();
flag1 = true;
}
if (((((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).m_ValidationMode == ValidationModes.MaskEdit) & ((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).Required) && (StringType.StrCmp(((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).Text, "", false) != 0))
{
int num9 = ((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).Text.Length - 1;
for (int num8 = 0; num8 <= num9; num8++)
{
if (StringType.StrCmp(StringType.FromChar(((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).Text[num8]), "_", false) == 0)
{
((ValidText.ValidText) pForm.Controls[num1].Controls[num2].Controls[num3].Controls[num4]).muestraRequired();
flag1 = true;
break;
}
}
}
}
}
}
}
}
if (flag1)
{
return false;
}
return true;
}

private void showError(Collection pInvalidCharacters)
{
if (pInvalidCharacters.Count > 1)
{
IEnumerator enumerator1;
string text1 = "";
try
{
enumerator1 = pInvalidCharacters.GetEnumerator();
while (enumerator1.MoveNext())
{
string text2 = StringType.FromObject(enumerator1.Current);
text1 = text1 + "'" + text2 + "', ";
}
}
finally
{
if (enumerator1 is IDisposable)
{
((IDisposable) enumerator1).Dispose();
}
}
switch (this.m_MessageLanguage)
{
case MessageLanguages.English:
{
this.erpShowError.SetError(this, "Characters (" + text1.Trim().Remove(text1.Length - 2, 1) + ") are not allowed!");
return;
}
case MessageLanguages.Español:
{
this.erpShowError.SetError(this, "Los caracteres (" + text1.Trim().Remove(text1.Length - 2, 1) + ") no son permitidos!");
return;
}
}
}
else
{
switch (this.m_MessageLanguage)
{
case MessageLanguages.English:
{
this.erpShowError.SetError(this, "Character ('" + StringType.FromObject(pInvalidCharacters[1]) + "') is not allowed!");
break;
}
case MessageLanguages.Español:
{
this.erpShowError.SetError(this, "El caracter ('" + StringType.FromObject(pInvalidCharacters[1]) + "') no es permitido!");
break;
}
}
}
}

public void ValidText_limpiaMaskEdit()
{
if (this.m_ValidationMode == ValidationModes.MaskEdit)
{
while (StringType.StrCmp(this.Text, this.maskString, false) != 0)
{
this.Text = this.maskString;
}
this.Select();
this.SelectionStart = 0;
}
}

public void ValidText_obtieneValor(string p_strValor)
{
if (this.m_ValidationMode == ValidationModes.MaskEdit)
{
while (StringType.StrCmp(this.Text, p_strValor, false) != 0)
{
this.Text = p_strValor;
}
}
}


internal virtual ErrorProvider erpShowError
{
get
{
return this._erpShowError;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (this._erpShowError != null)
{
}
this._erpShowError = value;
if (this._erpShowError != null)
{
}
}
}

internal virtual ErrorProvider erpShowRequired
{
get
{
return this._erpShowRequired;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (this._erpShowRequired != null)
{
}
this._erpShowRequired = value;
if (this._erpShowRequired != null)
{
}
}
}

[Category("Validation"), Description("Field name to validate. Field name will be showed in the field required error messages.")]
public string FieldReference
{
get
{
return this.m_FieldReference;
}
set
{
this.m_FieldReference = value;
}
}

[Category("Validation"), RefreshProperties(RefreshProperties.All), Description("Mask. #:Numbers, A:Uppercase, a: lowercase, &&:Uppercase and lowercase, $:Uppercase, lowercase and Numbers. Other characters are fixed in the mask.")]
public string MaskEdit
{
get
{
return this.m_MaskEdit;
}
set
{
this.m_MaskEdit = value;
if (StringType.StrCmp(this.m_MaskEdit, "", false) != 0)
{
this.ValidationMode = ValidationModes.MaskEdit;
}
}
}

[Description("Sets error icon messages language."), Category("Validation")]
public MessageLanguages MessageLanguage
{
get
{
return this.m_MessageLanguage;
}
set
{
this.m_MessageLanguage = value;
}
}

private Form miForm
{
get
{
return this._miForm;
}
[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (this._miForm != null)
{
this._miForm.Load -= new EventHandler(this.eventLoad_ValidTextForm);
}
this._miForm = value;
if (this._miForm != null)
{
this._miForm.Load += new EventHandler(this.eventLoad_ValidTextForm);
}
}
}

[Description("Sets regular expresssion Pattern to validate in RegularExpression validation mode."), Category("Validation")]
public RegularExpressionModes RegExPattern
{
get
{
return this.m_RegExPattern;
}
set
{
this.m_RegExPattern = value;
}
}

[Description("Sets the field as required for validation."), Category("Validation")]
public bool Required
{
get
{
return this.m_Required;
}
set
{
this.m_Required = value;
if (this.m_Required)
{
this.CausesValidation = true;
}
}
}

[Description("Sets if error icon is showed."), Category("Validation")]
public bool ShowErrorIcon
{
get
{
return this.m_ShowErrorIcon;
}
set
{
this.m_ShowErrorIcon = value;
}
}

[Category("Validation"), RefreshProperties(RefreshProperties.All), Description("Sets the validation mode to use.")]
public ValidationModes ValidationMode
{
get
{
return this.m_ValidationMode;
}
set
{
this.m_ValidationMode = value;
switch (this.m_ValidationMode)
{
case ValidationModes.None:
{
this.m_ValidText = "";
this.m_MaskEdit = "";
return;
}
case ValidationModes.ValidCharacters:
{
this.m_MaskEdit = "";
return;
}
case ValidationModes.InvalidCharacters:
{
this.m_MaskEdit = "";
return;
}
case ValidationModes.Letters:
{
this.m_MaskEdit = "";
return;
}
case ValidationModes.Numbers:
{
this.m_MaskEdit = "";
return;
}
case ValidationModes.MaskEdit:
{
if (this.ValidationMode == ValidationModes.MaskEdit)
{
if (StringType.StrCmp(this.m_MaskEdit, "", false) == 0)
{
this.m_MaskEdit = "Mask not set";
}
this.maskString = "";
this.maskValues = "";
string[,] textArray1 = this.getMask(this.m_MaskEdit);
int num2 = (int) Math.Round((double) ((((double) textArray1.Length) / 2) - 1));
for (int num1 = 0; num1 <= num2; num1++)
{
this.maskString = this.maskString + textArray1[num1, 0];
this.maskValues = this.maskValues + textArray1[num1, 1];
}
this.Text = this.maskString;
}
return;
}
}
}
}

[Description("ValidText, invalidText or regularExpression to use in validation."), Category("Validation")]
public string ValidText
{
get
{
return this.m_ValidText;
}
set
{
this.m_ValidText = value;
}
}


}
}

Yama Kamyar

QuestionC# Version??? Pin
.NET Follower16-Nov-04 19:48
.NET Follower16-Nov-04 19:48 
AnswerRe: C# Version??? Pin
Reader Man San15-Feb-09 21:50
professionalReader Man San15-Feb-09 21:50 
GeneralBug on line 613 ValidText.vb Pin
SAN Peter17-May-04 0:42
SAN Peter17-May-04 0:42 
GeneralRe: Bug on line 613 ValidText.vb Pin
Renaud Bédard1-Feb-05 9:37
Renaud Bédard1-Feb-05 9:37 
GeneralScary photo , man Pin
Anthony_Yio10-Oct-03 21:04
Anthony_Yio10-Oct-03 21:04 
GeneralHelp on Email validation Pin
mubavoice4-Oct-03 22:08
mubavoice4-Oct-03 22:08 
GeneralRe: Help on Email validation Pin
yamabiz15-Feb-06 11:05
yamabiz15-Feb-06 11:05 
Questioncomments? Pin
machocr2-Jun-03 11:36
machocr2-Jun-03 11:36 
AnswerRe: comments? Pin
Levi Erdmann7-Oct-03 9:34
Levi Erdmann7-Oct-03 9:34 
GeneralRe: comments? Pin
machocr7-Oct-03 11:21
machocr7-Oct-03 11:21 
GeneralRe: comments? Pin
Levi Erdmann7-Oct-03 11:23
Levi Erdmann7-Oct-03 11:23 
AnswerRe: comments? Pin
Timothy Paul Narron6-Jan-04 11:24
Timothy Paul Narron6-Jan-04 11:24 
AnswerRe: comments? Pin
Sidney James Fuerte5-Jan-06 21:54
Sidney James Fuerte5-Jan-06 21:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.