public void CaseSensitiveStringMatching() { RegularExpressionValidator validator = new RegularExpressionValidator("ToString()", "true", @"[A-Z][a-z]*"); Assert.IsTrue(validator.Validate("Aleksandar", new ValidationErrors())); Assert.IsFalse(validator.Validate("ALEKSANDAR", new ValidationErrors())); Assert.IsFalse(validator.Validate("aleksandar", new ValidationErrors())); }
protected void Page_Command(Object sender, CommandEventArgs e) { if (e.CommandName == "NewRecord") { reqLAST_NAME.Enabled = true; //reqPHONE_WORK.Enabled = true; // 07/16/2005 Paul. Phone is not currently validated. reqEMAIL1.Enabled = true; reqLAST_NAME.Validate(); reqPHONE_WORK.Validate(); reqEMAIL1.Validate(); if (Page.IsValid) { Guid gID = Guid.Empty; try { SqlProcs.spLEADS_New(ref gID, txtFIRST_NAME.Text, txtLAST_NAME.Text, txtPHONE_WORK.Text, txtEMAIL1.Text); } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); lblError.Text = ex.Message; } if (!Sql.IsEmptyGuid(gID)) { Response.Redirect("~/Leads/view.aspx?ID=" + gID.ToString()); } } else { reqEMAIL1.ErrorMessage = L10n.Term("Contacts.LBL_INVALID_EMAIL") + " " + txtEMAIL1.Text + "<br>"; } } }
protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e) { TextBox firstName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstName"); TextBox lastName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LastName"); Label firstNameValid = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstNameValid"); TextBox userName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"); TextBox eMail = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email"); Label emailValidBox = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("EmailValidBox"); RegularExpressionValidator reg = (RegularExpressionValidator)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RegEx"); reg.Validate(); bool myBool = true; emailValidBox.CssClass = "validbox"; if (reg.IsValid == false & myBool == true & eMail.Text != "") { myBool = false; e.Cancel = true; emailValidBox.CssClass = "validboxviz"; } using (CreditMaestroEntities ent = new CreditMaestroEntities()) { var checkEmail = ent.aspnet_Membership.Where(u => u.Email.Equals(eMail.Text)).SingleOrDefault(); if (checkEmail != null) { myBool = false; e.Cancel = true; DuplicateEmailPanel.Visible = true; } } }
public void WhitespaceStringOnlyValidatesToTrueWhenGivenMatchingRegex() { RegularExpressionValidator validator = new RegularExpressionValidator(); validator.Expression = @"\s*"; Assert.IsTrue(validator.Validate(" ", new ValidationErrors())); }
protected void btnCheckEmail_Click(object sender, EventArgs e) { RegularExpressionValidator.Validate(); if (Page.IsValid) { { string Query = "SELECT email_id FROM Customer Where email_id='" + txtEmailId.Text.ToString() + "'"; DataSet ds = z.FillDataset(Query); if (ds.Tables[0].Rows.Count > 0) { lblCheckEmail.Visible = true; lblCheckEmail.ForeColor = System.Drawing.Color.Red; lblCheckEmail.Font.Bold = true; lblCheckEmail.Text = "This E Mail Id Already Exists"; } else { lblCheckEmail.Visible = true; lblCheckEmail.ForeColor = System.Drawing.Color.Green; lblCheckEmail.Font.Bold = true; lblCheckEmail.Text = "This E Mail Id Is Availiable"; } } } }
protected void gvWorkstations_RowUpdating(object sender, GridViewUpdateEventArgs e) { TextBox n = this.gvWorkstations.Rows[gvWorkstations.EditIndex].Cells[0].FindControl("txtWorkstationName") as TextBox; TextBox mac = this.gvWorkstations.Rows[gvWorkstations.EditIndex].Cells[0].FindControl("txtMACAddress") as TextBox; DropDownList o = this.gvWorkstations.Rows[gvWorkstations.EditIndex].Cells[0].FindControl("ddlOS") as DropDownList; RequiredFieldValidator rfvName = this.gvWorkstations.Rows[gvWorkstations.EditIndex].Cells[0].FindControl("rfvClassroomName") as RequiredFieldValidator; RequiredFieldValidator rfvMac = this.gvWorkstations.Rows[gvWorkstations.EditIndex].Cells[0].FindControl("rfvMAC") as RequiredFieldValidator; RegularExpressionValidator revMac = this.gvWorkstations.Rows[gvWorkstations.EditIndex].Cells[0].FindControl("revMAC") as RegularExpressionValidator; rfvName.Validate(); rfvMac.Validate(); revMac.Validate(); if (rfvName.IsValid && rfvMac.IsValid && revMac.IsValid) { Workstation w = new Workstation(); w.edit(Convert.ToInt32(e.Keys[0].ToString()), n.Text, mac.Text, Convert.ToInt32(ddlClassroom.SelectedValue), 0, Convert.ToInt32(o.SelectedValue)); lblText.Text = "<br />Record modified successfully<br />"; gvWorkstations.EditIndex = -1; gvWorkstations.DataSource = w.load(Convert.ToInt32(this.ddlClassroom.SelectedValue)); gvWorkstations.DataBind(); this.gvWorkstations.ShowFooter = false; btnInsert.Visible = true; } }
protected void ListViewAnswers_ItemDataBound(object sender, ListViewItemEventArgs e) { ListView listViewComments = (ListView)e.Item.FindControl("RepeaterComment"); Data.Answer answer = ((Data.Answer)e.Item.DataItem); listViewComments.DataSource = answer.Comments; HyperLink answerEditLink = (HyperLink)e.Item.FindControl("HyperLinkAnswerEdit"); if (answer.UserId == User.Identity.GetUserId <int>()) { answerEditLink.Visible = true; } if (ViewState["RepeaterId"] != null && e.Item.ID == (string)ViewState["RepeaterId"]) { Panel reply = (Panel)e.Item.FindControl("CommentPanel"); reply.Visible = true; ViewState.Add("CurrentAnswerId", answer.Id); RegularExpressionValidator regExpValidator = (RegularExpressionValidator)e.Item.FindControl("RegularExpressionValidatorComment"); TextBox tb = (TextBox)e.Item.FindControl("TextBoxComment"); tb.Text = (string)ViewState["CommentText"]; regExpValidator.ControlToValidate = tb.ID; regExpValidator.Validate(); listViewComments.DataBind(); } else { listViewComments.DataBind(); } }
public void SunnyDay_Valid() { RegularExpressionValidator validator = new RegularExpressionValidator(); validator.Expression = @"((\d{1,2}\.\d{1,3}\.\d{1,3}\.\d{1,3}))"; Assert.IsTrue(validator.Validate("11.222.333.444", new ValidationErrors())); }
public void When_the_text_is_empty_then_the_validator_should_fail() { string input = ""; var validator = new RegularExpressionValidator(@"^\w\d$"); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => input)); result.IsValid().ShouldBeFalse(); }
public void WhenValidatorIsNotEvaluatedBecauseWhenExpressionReturnsFalse() { RegularExpressionValidator validator = new RegularExpressionValidator("'ljwdf87cwbh'", "false", @"((\d{1,2}\.\d{1,3}\.\d{1,3}\.\d{1,3}))"); bool valid = validator.Validate(null, new ValidationErrors()); Assert.IsTrue(valid, "Validation should succeed when regex validator is not evaluated."); }
public void When_the_text_matches_the_regular_expression_then_the_validator_should_pass() { string input = "S3"; var validator = new RegularExpressionValidator(@"^\w\d$"); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => input)); result.IsValid().ShouldBeTrue(); }
protected void Page_Command(Object sender, CommandEventArgs e) { if (e.CommandName == "NewRecord") { reqNAME.Enabled = true; //reqPHONE_OFFICE.Enabled = true; // 07/16/2005 Paul. Phone is not currently validated. reqNAME.Validate(); reqPHONE_OFFICE.Validate(); if (Page.IsValid) { Guid gID = Guid.Empty; try { SqlProcs.spACCOUNTS_New(ref gID, txtNAME.Text, txtPHONE_OFFICE.Text, txtWEBSITE.Text); } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message); lblError.Text = ex.Message; } if (!Sql.IsEmptyGuid(gID)) { Response.Redirect("~/Accounts/view.aspx?ID=" + gID.ToString()); } } } }
public void AllowPartialMatching() { RegularExpressionValidator validator = new RegularExpressionValidator(); validator.Expression = "[A-Za-z]"; validator.AllowPartialMatching = true; Assert.True(validator.Validate("123a456", new ValidationErrors())); }
private void searchButton_Click(object sender, EventArgs e) { Form1 form = (Form1)Owner; if (RegularExpressionValidator.Validate(form, regularExpressionTextBox.Text, denyRegexCheckBox.Checked)) { FileListManager.SetNewRecentPattern(this, regularExpressionTextBox.Text); } }
protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e) { TextBox firstName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstName"); TextBox lastName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LastName"); Label firstNameValid = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstNameValid"); TextBox userName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"); Label userNameValid = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserNameValid"); TextBox password = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Password"); TextBox confPassword = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ConfirmPassword"); Label passwordValidBox = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("PasswordValidBox"); Label confValidBox = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ConfValidBox"); TextBox eMail = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email"); Label emailValidBox = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("EmailValidBox"); RegularExpressionValidator reg = (RegularExpressionValidator)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RegEx"); reg.Validate(); bool myBool = true; firstNameValid.CssClass = "validbox"; userNameValid.CssClass = "validbox"; passwordValidBox.CssClass = "validbox"; emailValidBox.CssClass = "validbox"; confValidBox.CssClass = "none"; if (firstName.Text == "" & myBool == true || firstName.Text == null & myBool == true) { myBool = false; e.Cancel = true; firstNameValid.CssClass = "validboxviz"; } if (userName.Text == "" & myBool == true || userName.Text == null & myBool == true) { myBool = false; e.Cancel = true; userNameValid.CssClass = "validboxviz"; } if (password.Text.Length < 6 & myBool == true) { myBool = false; e.Cancel = true; passwordValidBox.CssClass = "validboxviz"; } if (confPassword.Text != password.Text & myBool == true) { myBool = false; e.Cancel = true; confValidBox.CssClass = "validboxviz"; } if (reg.IsValid == false & myBool == true & eMail.Text != "") { myBool = false; e.Cancel = true; emailValidBox.CssClass = "validboxviz"; } }
protected void Page_Load(object sender, EventArgs e) { RegularExpressionValidator reg = new RegularExpressionValidator(); reg.ID = "RegularExpressionValidator1"; reg.ControlToValidate = "TextBox1"; reg.Display = ValidatorDisplay.Dynamic; reg.ErrorMessage = "your Error message"; reg.SetFocusOnError = true; reg.ValidationExpression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"; form1.Controls.Add(reg); reg.Validate(); }
protected void btnActCodeSender_Click(object sender, EventArgs e) { RequiredEmail.Validate(); RegularExpressionValidator.Validate(); if (RegularExpressionValidator.IsValid && RequiredEmail.IsValid) { _actCode = TextHelper.RandomNumber(4); Email.SendGmail("*****@*****.**", "ma8635047", email.Value, "Mã kích hoạt đăng ký", $"Mã kích hoạt của bạn là {_actCode}"); Alert($"alert('Đã gửi mã kích hoạt đến {email.Value}')"); } }
public bool Validar(bool validarControlInterno) { if (validarControlInterno) { RequiredFieldValidator valRequeridoCalle = (RequiredFieldValidator)this.phValidCalle.FindControl("valRequeridoCalle"); RegularExpressionValidator valDescripcionCalle = (RegularExpressionValidator)this.phValidCalle.FindControl("valDescripcionCalle"); RegularExpressionValidator valEnteroNroCalle = (RegularExpressionValidator)this.phValidCalleNro.FindControl("valEnteroNroCalle"); //RequiredFieldValidator valRequeridoTelefono = (RequiredFieldValidator)this.phValidTelefono.FindControl("valRequeridoTelefono"); //RequiredFieldValidator valRequeridoProvincia = (RequiredFieldValidator)this.phValidCalle.FindControl("valRequeridoProvincia"); //RequiredFieldValidator valRequeridoLocalidad = (RequiredFieldValidator)this.phValidCalle.FindControl("valRequeridoLocalidad"); CustomValidator cstmValidatorProvincia = (CustomValidator)phValidProvincia.FindControl("cstmValidatorProvincia"); CustomValidator cstmValidatorLocalidad = (CustomValidator)phValidLocalidad.FindControl("cstmValidatorLocalidad"); valRequeridoCalle.Enabled = true; valDescripcionCalle.Enabled = true; valEnteroNroCalle.Enabled = true; //valRequeridoTelefono.Enabled = true; cstmValidatorProvincia.Enabled = true; cstmValidatorLocalidad.Enabled = true; valRequeridoCalle.Validate(); valDescripcionCalle.Validate(); valEnteroNroCalle.Validate(); //valRequeridoTelefono.Validate(); cstmValidatorProvincia.Validate(); cstmValidatorLocalidad.Validate(); if (valRequeridoCalle.IsValid && valDescripcionCalle.IsValid && valEnteroNroCalle.IsValid && cstmValidatorProvincia.IsValid && cstmValidatorLocalidad.IsValid) { return(true); } else { return(false); } } else { RequiredFieldValidator valRequeridoCalle = (RequiredFieldValidator)this.phValidCalle.FindControl("valRequeridoCalle"); RegularExpressionValidator valDescripcionCalle = (RegularExpressionValidator)this.phValidCalle.FindControl("valDescripcionCalle"); RegularExpressionValidator valEnteroNroCalle = (RegularExpressionValidator)this.phValidCalleNro.FindControl("valEnteroNroCalle"); //RequiredFieldValidator valRequeridoTelefono = (RequiredFieldValidator)this.phValidTelefono.FindControl("valRequeridoTelefono"); RequiredFieldValidator valRequeridoProvincia = (RequiredFieldValidator)this.phValidCalle.FindControl("valRequeridoProvincia"); RequiredFieldValidator valRequeridoLocalidad = (RequiredFieldValidator)this.phValidCalle.FindControl("valRequeridoLocalidad"); valRequeridoCalle.Enabled = false; valDescripcionCalle.Enabled = false; valEnteroNroCalle.Enabled = false; //valRequeridoTelefono.Enabled = true; valRequeridoProvincia.Enabled = false; valRequeridoLocalidad.Enabled = false; return(true); } }
/// <summary> /// When overridden in a derived class, this method contains the code to determine whether the value in the input control is valid. /// </summary> /// <returns> /// true if the value in the input control is valid; otherwise, false. /// </returns> protected override bool EvaluateIsValid() { if (this.rangeValidator != null) { rangeValidator.Validate(); if (!this.rangeValidator.IsValid) { return(false); } } if (this.requiredFieldValidator != null) { requiredFieldValidator.Validate(); if (!this.requiredFieldValidator.IsValid) { return(false); } } if (this.compareValidator != null) { compareValidator.Validate(); if (!this.compareValidator.IsValid) { return(false); } } if (this.regularExpressionValidator != null) { regularExpressionValidator.Validate(); if (!this.regularExpressionValidator.IsValid) { return(false); } } if (this.customStringLengthValidator != null) { customStringLengthValidator.Validate(); if (!this.customStringLengthValidator.IsValid) { return(false); } } return(true); }
private void ValidateMovimientos(object source, System.Web.UI.WebControls.ServerValidateEventArgs args) { RequiredFieldValidator reqMov = (RequiredFieldValidator)this.phValidMovimientoMensual.FindControl("reqMov"); RegularExpressionValidator valMov = (RegularExpressionValidator)this.phValidMovimientoMensual.FindControl("valMov"); reqMov.Enabled = true; valMov.Enabled = true; reqMov.Validate(); valMov.Validate(); if (!reqMov.IsValid || !valMov.IsValid) { args.IsValid = false; return; } args.IsValid = true; }
public override void Validate() { string valClientId = null; if (!ReadOnly) { base.Validate(); IsValid = RequiredFieldValidator.IsValid; valClientId = RequiredFieldValidator.ClientID; } if (RangeValidationEnabled) { if (IsValid) { m_RangeValidator.Validate(); IsValid = m_RangeValidator.IsValid; valClientId = m_RangeValidator.ClientID; } } if (RegularExpressionValidationEnabled) { if (IsValid) { m_RegularExpressionValidator.Validate(); IsValid = m_RegularExpressionValidator.IsValid; valClientId = m_RegularExpressionValidator.ClientID; } } if (this.Theme == MasterPageTheme.Modern) { if (!IsValid) { this.CssClass += " Invalid"; this.Attributes["validatorId"] = valClientId; } } }
public void WithNull() { RegularExpressionValidator validator = new RegularExpressionValidator(); Assert.Throws <ArgumentException>(() => validator.Validate(null, new ValidationErrors())); }
public void SunnyDayFailure_Invalid() { RegularExpressionValidator validator = new RegularExpressionValidator(Expression.Parse("'ljwdf87cwbh'"), Expression.Parse("true"), @"((\d{1,2}\.\d{1,3}\.\d{1,3}\.\d{1,3}))"); Assert.IsFalse(validator.Validate("ljwdf87cwbh", new ValidationErrors())); }
public void WhitespaceStringDoesntEvaluateToTrueByDefault() { RegularExpressionValidator validator = new RegularExpressionValidator(); Assert.IsFalse(validator.Validate(" ", new ValidationErrors())); }
public void WithNull() { RegularExpressionValidator validator = new RegularExpressionValidator(); validator.Validate(null, new ValidationErrors()); }
public void EmptyStringValidatesToTrue() { RegularExpressionValidator validator = new RegularExpressionValidator(); Assert.IsTrue(validator.Validate(string.Empty, new ValidationErrors())); }
protected void Page_Command(Object sender, CommandEventArgs e) { if (e.CommandName == "NewRecord") { txtNAME.Text = txtNAME.Text.Trim(); txtLABEL.Text = txtLABEL.Text.Trim(); if (Sql.IsEmptyString(txtLABEL.Text)) { txtLABEL.Text = txtNAME.Text; } Regex r = new Regex(@"[^\w]+"); txtNAME.Text = r.Replace(txtNAME.Text, "_"); // 01/11/2006 Paul. The label does not need to be validated because it will become the term display name. reqNAME.Enabled = true; regNAME.Enabled = true; reqNAME.Validate(); regNAME.Validate(); if (Page.IsValid) { Guid gID = Guid.Empty; try { // 01/11/2006 Paul. The label needs to be stored in the TERMINOLOGY table. // 05/20/2007 Paul. The Label term is no longer used. The label term must be derived from the field name // in order for the reporting area to work properly. The reporting area assumes that the label is the of the format "LBL_" + Name + "_C". string sLABEL_TERM = String.Empty; // r.Replace(txtLABEL.Text, "_"); // 04/24/2006 Paul. Upgrade to SugarCRM 4.2 Schema. // 04/24/2006 Paul. We don't support MassUpdate at this time. // 07/18/2006 Paul. Manually create the command so that we can increase the timeout. // 07/18/2006 Paul. Keep the original procedure call so that we will get a compiler error if something changes. bool bIncreaseTimeout = true; if (!bIncreaseTimeout) { SqlProcs.spFIELDS_META_DATA_Insert(ref gID, txtNAME.Text, txtLABEL.Text, sLABEL_TERM, sMODULE_NAME, lstDATA_TYPE.SelectedValue, Sql.ToInteger(txtMAX_SIZE.Text), chkREQUIRED.Checked, chkAUDITED.Checked, txtDEFAULT_VALUE.Text, lstDROPDOWN_LIST.SelectedValue, false); } else { string sNAME = txtNAME.Text; string sLABEL = txtLABEL.Text; string sCUSTOM_MODULE = sMODULE_NAME; string sDATA_TYPE = lstDATA_TYPE.SelectedValue; Int32 nMAX_SIZE = Sql.ToInteger(txtMAX_SIZE.Text); bool bREQUIRED = chkREQUIRED.Checked; bool bAUDITED = chkAUDITED.Checked; string sDEFAULT_VALUE = txtDEFAULT_VALUE.Text; string sDROPDOWN_LIST = lstDROPDOWN_LIST.SelectedValue; bool bMASS_UPDATE = false; DbProviderFactory dbf = DbProviderFactories.GetFactory(); using (IDbConnection con = dbf.CreateConnection()) { con.Open(); using (IDbTransaction trn = con.BeginTransaction()) { try { using (IDbCommand cmd = con.CreateCommand()) { cmd.Transaction = trn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "spFIELDS_META_DATA_Insert"; // 07/18/2006 Paul. Tripple the default timeout. The operation was timing-out on QA machines and on the demo server. // 02/03/2007 Paul. Increase timeout to 5 minutes. It should not take that long, but some users are reporting a timeout. cmd.CommandTimeout = 5 * 60; IDbDataParameter parID = Sql.AddParameter(cmd, "@ID", gID); IDbDataParameter parMODIFIED_USER_ID = Sql.AddParameter(cmd, "@MODIFIED_USER_ID", Security.USER_ID); IDbDataParameter parNAME = Sql.AddParameter(cmd, "@NAME", sNAME, 255); IDbDataParameter parLABEL = Sql.AddParameter(cmd, "@LABEL", sLABEL, 255); IDbDataParameter parLABEL_TERM = Sql.AddParameter(cmd, "@LABEL_TERM", sLABEL_TERM, 255); IDbDataParameter parCUSTOM_MODULE = Sql.AddParameter(cmd, "@CUSTOM_MODULE", sCUSTOM_MODULE, 255); IDbDataParameter parDATA_TYPE = Sql.AddParameter(cmd, "@DATA_TYPE", sDATA_TYPE, 255); IDbDataParameter parMAX_SIZE = Sql.AddParameter(cmd, "@MAX_SIZE", nMAX_SIZE); IDbDataParameter parREQUIRED = Sql.AddParameter(cmd, "@REQUIRED", bREQUIRED); IDbDataParameter parAUDITED = Sql.AddParameter(cmd, "@AUDITED", bAUDITED); IDbDataParameter parDEFAULT_VALUE = Sql.AddParameter(cmd, "@DEFAULT_VALUE", sDEFAULT_VALUE, 255); IDbDataParameter parDROPDOWN_LIST = Sql.AddParameter(cmd, "@DROPDOWN_LIST", sDROPDOWN_LIST, 50); IDbDataParameter parMASS_UPDATE = Sql.AddParameter(cmd, "@MASS_UPDATE", bMASS_UPDATE); parID.Direction = ParameterDirection.InputOutput; cmd.ExecuteNonQuery(); gID = Sql.ToGuid(parID.Value); } trn.Commit(); } catch (Exception ex) { trn.Rollback(); throw(new Exception(ex.Message, ex.InnerException)); } } } } // 01/11/2006 Paul. Add term to the local cache. Always default to english. //Application["en-US." + sMODULE_NAME + "." + sLABEL_TERM] = txtLABEL.Text; // 04/05/2006 Paul. A _C is appended to the term in the procedure. Do so here as well. // 05/20/2007 Paul. The label is also prepended with LBL_. This is a requirement for the reporting system. // 05/20/2007 Paul. The Label term is no longer used. The label term must be derived from the field name // in order for the reporting area to work properly. The reporting area assumes that the label is the of the format "LBL_" + Name + "_C". L10N.SetTerm("en-US", sMODULE_NAME, "LBL_" + txtNAME.Text.ToUpper() + "_C", txtLABEL.Text); // 01/10/2006 Paul. Clear the cache. SplendidCache.ClearFieldsMetaData(sMODULE_NAME); Clear(); if (Command != null) { Command(this, e); } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex); lblError.Text = ex.Message; } } } }
public void When_validation_fails_the_default_error_should_be_set() { string input = "S33"; var validator = new RegularExpressionValidator(@"^\w\d$"); var result = validator.Validate(new PropertyValidatorContext("Name", new object(), x => input)); result.Single().ErrorMessage.ShouldEqual("'Name' is not in the correct format."); }
public void WithNonString() { RegularExpressionValidator validator = new RegularExpressionValidator(); validator.Validate(this, new ValidationErrors()); }
protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e) { TextBox firstName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstName"); TextBox lastName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LastName"); Label firstNameValid = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstNameValid"); TextBox userName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"); Label userNameValid = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserNameValid"); Label userNameInUseLabel = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserNameInUseLabel"); TextBox password = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Password"); TextBox confPassword = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ConfirmPassword"); Label passwordValidBox = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("PasswordValidBox"); Label confValidBox = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ConfValidBox"); TextBox eMail = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email"); Label emailValidBox = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("EmailValidBox"); RegularExpressionValidator reg = (RegularExpressionValidator)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RegEx"); reg.Validate(); bool myBool = true; firstNameValid.CssClass = "validbox"; userNameValid.CssClass = "validbox"; passwordValidBox.CssClass = "validbox"; emailValidBox.CssClass = "validbox"; confValidBox.CssClass = "none"; if (firstName.Text == "" & myBool == true || firstName.Text == null & myBool == true) { myBool = false; e.Cancel = true; firstNameValid.CssClass = "validboxviz"; } if (userName.Text == "" & myBool == true || userName.Text == null & myBool == true || userName.Text.Length < 5 & myBool == true || userName.Text.Length > 15 & myBool == true) { myBool = false; e.Cancel = true; userNameValid.CssClass = "validboxviz"; } if (password.Text.Length < 6 & myBool == true) { myBool = false; e.Cancel = true; passwordValidBox.CssClass = "validboxviz"; } if (confPassword.Text != password.Text & myBool == true) { myBool = false; e.Cancel = true; confValidBox.CssClass = "validboxviz"; } if (reg.IsValid == false & myBool == true & eMail.Text != "") { myBool = false; e.Cancel = true; emailValidBox.CssClass = "validboxviz"; } using (SwapEntities ent = new SwapEntities()) { var checkUsername = ent.aspnet_Users.Where(u => u.UserName.Equals(userName.Text)).SingleOrDefault(); if (checkUsername != null) { myBool = false; e.Cancel = true; userNameInUseLabel.CssClass = "validboxviz"; } } }
private void butGuardarTarifario_Click(object sender, System.EventArgs e) { RequiredFieldValidator reqDescrip = (RequiredFieldValidator)this.phValidTarifarioDescrip.FindControl("reqDescrip"); RegularExpressionValidator valDescrip = (RegularExpressionValidator)this.phValidTarifarioDescrip.FindControl("valDescrip"); reqDescrip.Enabled = true; valDescrip.Enabled = true; reqDescrip.Validate(); valDescrip.Validate(); if (!reqDescrip.IsValid || !valDescrip.IsValid) { return; } //Habilitar CustomValidator valValorizacion = (CustomValidator)this.phValidValorizacion.FindControl("valValorizacion"); valValorizacion.Enabled = true; valValorizacion.Validate(); if (!valValorizacion.IsValid) { return; } RegularExpressionValidator valImporteKgExc = (RegularExpressionValidator)this.phValidImporteKgExcedente.FindControl("valImporteKgExc"); valImporteKgExc.Enabled = true; valImporteKgExc.Validate(); if (!valImporteKgExc.IsValid) { return; } CustomValidator valImporte = (CustomValidator)this.phValidImporteKgExcedente.FindControl("valImporte"); valImporte.Enabled = true; valImporte.Validate(); if (!valImporte.IsValid) { return; } // Obtenemos el usuario que ejecuta la acción. IUsuarios usuarioConectado = UsuariosFactory.GetUsuario(); usuarioConectado.Login = this.UsuarioConectadoID; usuarioConectado.ConsultarByLogin(); if (chkVariacionTarifario.Checked) { if (rbtImporte.Checked && ddlTarifarioReferencia.SelectedIndex > 0 && chkVariacionTarifario.Checked) { RequiredFieldValidator reqImporteAjuste = (RequiredFieldValidator)this.phValidImporteAjuste.FindControl("reqImporteAjuste"); RegularExpressionValidator valImporteAjuste = (RegularExpressionValidator)this.phValidImporteAjuste.FindControl("valImporteAjuste"); reqImporteAjuste.Enabled = true; valImporteAjuste.Enabled = true; valImporteAjuste.Validate(); reqImporteAjuste.Validate(); if (!reqImporteAjuste.IsValid || !valImporteAjuste.IsValid) { return; } /*if(Convert.ToDouble(txtImporteAjuste.Text)==0) * { * ((ErrorWeb)this.phErrores.Controls[0]).setMensaje(this.TraducirTexto("Errores.Invalidos.ImportePositivo")); * return; * }*/ } else if (rbtPorcentaje.Checked && ddlTarifarioReferencia.SelectedIndex > 0 && chkVariacionTarifario.Checked) { RequiredFieldValidator reqPorcenAjuste = (RequiredFieldValidator)this.phValidImporteAjuste.FindControl("reqPorcenAjuste"); RegularExpressionValidator valPorcenAjuste = (RegularExpressionValidator)this.phValidImporteAjuste.FindControl("valPorcenAjuste"); reqPorcenAjuste.Enabled = true; valPorcenAjuste.Enabled = true; reqPorcenAjuste.Validate(); valPorcenAjuste.Validate(); if (!reqPorcenAjuste.IsValid || !valPorcenAjuste.IsValid) { return; } if (Convert.ToDouble(txtPorcentajeAjuste.Text) == 0) { ((ErrorWeb)this.phErrores.Controls[0]).setMensaje(this.TraducirTexto("Errores.Invalidos.Porcentaje")); return; } } } //Ver de habilitar todos los validadores y nunca usar el Page.Validate //Page.Validate(); //if (!Page.IsValid) // return; tari = (ITarifario)Session["tarifario"]; //Verificar si hubo cambios...ver si acepta que se realice un recalculo de los importes bool okChange = CambiaronDatos(); tari.UnidadNegocioID = this.UnidadNegocioID; tari.EsTarifarioGeneral = chkTarifarioGeneral.Checked; //tari.ImporteKgExcedente=Convert.ToDouble(this.txtImporteKgExcedente.Text); tari.TarifarioDescrip = this.txtTarifarioDescrip.Text.Trim(); if (ddlValorizacion.SelectedIndex > 0) { tari.ValorizacionTarifario = (NegociosSisPackInterface.SisPack.ValorizacionTarifario)Convert.ToInt32(ddlValorizacion.SelectedValue); } else { tari.ValorizacionTarifario = (NegociosSisPackInterface.SisPack.ValorizacionTarifario)Convert.ToInt32(this.txtValorizacionSelec.Text); } if (this.txtImporteKgExcedente.Text != "") { tari.ImporteKgExcedente = Convert.ToDouble(this.txtImporteKgExcedente.Text); } else { tari.ImporteKgExcedente = Convert.ToDouble(this.txtImporteKg.Text); } if (ddlTarifarioReferencia.SelectedIndex > 0) { tari.TarifarioRefID = Convert.ToInt32(ddlTarifarioReferencia.SelectedValue); if (chkVariacionTarifario.Checked) { if (rbtPorcentaje.Checked) { tari.PorcentajeAjuste = Convert.ToDouble(this.txtPorcentajeAjuste.Text); tari.ImporteAjuste = 0; //Ver si esto queda this.txtImporteAjuste.Text = ""; } else { tari.ImporteAjuste = Convert.ToDouble(this.txtImporteAjuste.Text); tari.PorcentajeAjuste = 0; //Ver si esto queda this.txtPorcentajeAjuste.Text = ""; } if (rbtFactorPositivo.Checked) { tari.FactorAjuste = "+"; } else { tari.FactorAjuste = "-"; } } else { tari.FactorAjuste = ""; tari.PorcentajeAjuste = 0; tari.ImporteAjuste = 0; this.txtPorcentajeAjuste.Text = ""; this.txtImporteAjuste.Text = ""; } } /*SFE Guardar el Importe Minimo de Valor Declarado para el tipo de Valorizacion Valor Declarado*/ if (tari.ValorizacionTarifario == NegociosSisPackInterface.SisPack.ValorizacionTarifario.ValorDeclarado) { tari.ImporteMinimoValorDeclarado = Utiles.Validaciones.obtieneDouble(this.txtImporteMinValorDeclarado.Text); RegularExpressionValidator valImporteMinValorDeclarado = (RegularExpressionValidator)this.phValidImporteMinimo.FindControl("valImporteMinValorDeclarado"); valImporteMinValorDeclarado.Enabled = true; valImporteMinValorDeclarado.Validate(); if (!valImporteMinValorDeclarado.IsValid) { return; } } Label lblResul = new Label(); try { //Si cambiaron los datos tengo que empezar una transaccion en la que guarde todo. if (okChange) { if (AdministrarTarifarios.RecalcularImportesTarifarioTope(tari, this.Request.QueryString["Tipo"], usuarioConectado.UsuarioID)) { tari.Guardar(usuarioConectado.UsuarioID); Session["tarifario"] = tari; this.ConsultarTarifario(); this.LoadUCTopes(); //this.LoadUCZonasTopes(); } } else { if (tari.Guardar(usuarioConectado.UsuarioID)) { txtTarifarioID.Text = tari.TarifarioID.ToString(); if (!modal) { string mensaje = "Los datos se guardaron correctamente. "; string script = "<script language='javascript'>\n"; script += "alert('" + mensaje + "');"; script += "</script>"; //Page.RegisterStartupScript("scriptOk", script); Page.RegisterClientScriptBlock("scriptOK", script); } Session["tarifario"] = tari; this.LoadUCTopes(); this.ConsultarTarifario(); } } // this.SetUC(); } catch (Exception ex) { string mensaje = ex.Message; try { mensaje = this.TraducirTexto(ex.Message); if (mensaje == "" || mensaje == null) { mensaje = ex.Message; } } catch (Exception) { mensaje = ex.Message; } ((ErrorWeb)this.phErrores.Controls[0]).setMensaje(mensaje); } }
private void butAgregar_Click(object sender, System.EventArgs e) { if (error) { ((ErrorWeb)this.phErrores.Controls[0]).setMensaje(this.TraducirTexto("Errores.Invalidos.LocalidadYaVinculada")); return; } RequiredFieldValidator reqProvincia = (RequiredFieldValidator)this.phValidProvinciaOrigen.FindControl("reqProvincia"); reqProvincia.Enabled = true; reqProvincia.Validate(); if (!reqProvincia.IsValid) { return; } /*RequiredFieldValidator reqLocalidad = (RequiredFieldValidator)this.phValidLocalidadOrigen.FindControl("reqLocalidad"); * reqLocalidad.Enabled = true; * reqLocalidad.Validate(); * if(!reqLocalidad.IsValid) * return;*/ if (this.ckTomarLocalidadReferencia.Checked == false) { if (dtgLocalidades.EditItemIndex == -1) { IraUltimaPagina(); DsKmsLocalidad ds = (DsKmsLocalidad)Session["dsKmsLocalidad"]; DsKmsLocalidad.DatosRow dr = ds.Datos.NewDatosRow(); dr.LocalidadOrigenID = (this.txtLocalidadSelec.Text == "" ? 0 : Convert.ToInt32(this.txtLocalidadSelec.Text)); dr.LocalidadDestinoID = 0; dr.ProvinciaDestinoDescrip = ""; dr.LocalidadDestinoDescrip = ""; dr.Baja = false; dr.Kms = 0; dr.ZonaDescrip = ""; dr.ProvinciaDestinoID = 0; /*try * {*/ ds.Datos.AddDatosRow(dr); /*} * catch(Exception){}*/ Session["dsKmsLocalidad"] = ds; int iNewItemIndex = this.dtgLocalidades.Items.Count; /*if (iNewItemIndex >= this.dtgLocalidades.PageSize) * { * this.dtgLocalidades.CurrentPageIndex++; * iNewItemIndex = 0; * }*/ this.dtgLocalidades.DataSource = (DsKmsLocalidad)Session["dsKmsLocalidad"]; this.dtgLocalidades.EditItemIndex = iNewItemIndex; this.dtgLocalidades.DataBind(); } } else if (this.ckTomarLocalidadReferencia.Checked == true) { RequiredFieldValidator reqProvinciaReferencia = (RequiredFieldValidator)this.phValidProvinciaReferencia.FindControl("reqProvinciaReferencia"); reqProvinciaReferencia.Enabled = true; reqProvinciaReferencia.Validate(); if (!reqProvinciaReferencia.IsValid) { return; } /*RequiredFieldValidator reqLocalidadReferencia = (RequiredFieldValidator)this.phValidLocalidadReferencia.FindControl("reqLocalidadReferencia"); * reqLocalidadReferencia.Enabled = true; * reqLocalidadReferencia.Validate(); * if(!reqLocalidadReferencia.IsValid) * return;*/ RequiredFieldValidator reqKmsReferencia = (RequiredFieldValidator)this.phValidKmsReferencia.FindControl("reqKmsReferencia"); reqKmsReferencia.Enabled = true; reqKmsReferencia.Validate(); if (!reqKmsReferencia.IsValid) { return; } RegularExpressionValidator valKmsReferencia = (RegularExpressionValidator)this.phValidKmsReferencia.FindControl("valKmsReferencia"); valKmsReferencia.Enabled = true; valKmsReferencia.Validate(); if (!valKmsReferencia.IsValid) { return; } IKmsLocalidad kmsLocalidad = KmsLocalidadFactory.GetKmsLocalidad(); kmsLocalidad.LocalidadOrigenID = Convert.ToInt32(this.txtLocalidadSelec.Text); kmsLocalidad.LocalidadOrigenRefID = Convert.ToInt32(this.txtLocalidadSelecReferencia.Text); kmsLocalidad.KmsRef = Convert.ToInt32(this.txtKmsReferencia.Text); kmsLocalidad.FactorAjuste = this.rbFactorAjusteNegativo.Checked ? false : true; Session["dsKmsLocalidad"] = (DsKmsLocalidad)kmsLocalidad.GuardarCruceLocalidadesbyLocalidadReferencia(); this.BindGrilla(0); } }
public void WithNull() { RegularExpressionValidator validator = new RegularExpressionValidator(); Assert.Throws<ArgumentException>(() => validator.Validate(null, new ValidationErrors())); }