 |
|
 |
I apologize for my coltishness.
|
|
|
|
 |
|
 |
what is the use of mask field i dint get use of it clearly
thnks for code but for novice users like me cannot use it just like that as we dont know how to use custom control .Hope u would add it soon ...any way thank u once again
have great time
|
|
|
|
 |
|
 |
wow this code is awesome ! great job !!
|
|
|
|
 |
|
 |
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 = @"(?[01]?\d\d?|2[0-4]\d|25[0-5])\.(?[01]?\d\d?|2[0-4]\d|25[0-5])\.(?[01]?\d\d?|2[0-4]\d|25[0-5])\.(?[01]?\d\d?|2[0-4]\d|25[0-5])(?x) ";
this.URL = @"^(?\w+)://[^/]+?(?:\d+)?/";
this.DATEC = @"(?\d{1,2})/(?\d{1,2})/(?(?:\d{4}|\d{2}))(?x)";
this.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
|
|
|
|
 |
|
 |
No comments when is the c# version coming....
|
|
|
|
 |
|
|
 |
|
 |
Hi,
i got an error (System.IndexOutOfRangeException) on line 613 in ValidText.vb.
How to got the error:
Set a textbox to maskedit ##/##/####.
Run the app and input all digits in the maskeditbox.
then cancel one digit and write another digit in replacment.
now the error occurs.
|
|
|
|
 |
|
 |
I encountered the same error and had to fix the code myself... it's actually pretty easy.
Just make a KeyDown event which traps the "Keys.Delete" and give it the "BackSP" flag, just like the backspace key. There.
A fixed release would be good
Zaknafein [zaknafein@defocused-soft.net]
|
|
|
|
 |
|
 |
Your photo seems scary to me.
Sonork 100.41263:Anthony_Yio
|
|
|
|
 |
|
 |
i have added your control to my usercontrol
now my requirement is to validated the email
i did all the properties settings and it is also showing the
error icon near the corresponding text box. But can u please tell
me which property will give me weather error occured or not. So that
i can do someother operation corresponding to that.
|
|
|
|
 |
|
 |
Hi you can add something like a public boolean the initially set it to false then set it to true everytime an error is returned from validText. You must add it to validText class...
Yama
|
|
|
|
 |
|
 |
Ya he coregido varios bugs ,le agregué un ìcono que serà visible desde el toolbox o cuadro de herramientas, además le agregue la posibilidad de escoger el idioma en los mensajes de error.
Futuro:
Estoy aprendiendo màs sobre expresiones regurales para evitar tener que usar ciclos para recorrer las cadenas o strings que me permiten hacer las validaciones de entrada de caracteres, y así mejorar la rapidez.
Si reconocen algùn error màs por favor haganmelo saber así como errores de traducción, sugerencias, mejoras y nuevas caracterìsticas que le agreguen.
Este control totalmente libre.
Espero que lo encuentren útil como yo.
Atte., Luis Alberto Ruiz, Costa Rica
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
 |
|
 |
I really like the maskEdit functionality.
The biggest problem I see is that there is no documentation, not even comments in the code.
|
|
|
|
 |
|
 |
Ok, im workink on it. and in CSharp
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
 |
|
 |
Cool! I was really wishing that the control was in C#, because man that's a lot of stuff to translate.
|
|
|
|
 |
|
 |
How is the C# version coming along?
|
|
|
|
 |
|
 |
Ummm... I was just browsing for new stuff here in CP and I bumped into this article. I was just wondering if a Final Version of this will come out soon Please keep us posted
Thanks/Regards
Sidney
TheMan!
|
|
|
|
 |
|