using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CMS.FormControls; using CMS.GlobalHelper; public partial class CMSFormControls_Inputs_EmailInput : FormEngineUserControl { #region "Properties" /// /// Gets or sets the enabled state of the control. /// public override bool Enabled { get { return base.Enabled; } set { base.Enabled = value; txtEmailInput.Enabled = value; } } /// /// Gets or sets field value. /// public override object Value { get { return txtEmailInput.Text.Trim(); } set { txtEmailInput.Text = (string)value; } } /// /// Gets ClientID of the textbox with emailinput. /// public override string ValueElementID { get { return txtEmailInput.ClientID; } } private bool mAllowMultipleAddresses = false; /// /// Gets or sets if multiple e-mail addresses can be entered. /// public bool AllowMultipleAddresses { get { return mAllowMultipleAddresses; } set { mAllowMultipleAddresses = value; } } /// /// Gets or sets string that should be used to delimit multiple addresses (default separator is semicolon - ;). /// public string EmailSeparator { get; set; } #endregion #region "Methods" /// /// Page load. /// protected void Page_Load(object sender, EventArgs e) { // Set control style and css class if (!string.IsNullOrEmpty(ControlStyle)) { txtEmailInput.Attributes.Add("style", ControlStyle); } if (!string.IsNullOrEmpty(CssClass)) { txtEmailInput.CssClass = CssClass; CssClass = null; } // Set additional properties AllowMultipleAddresses = ValidationHelper.GetBoolean(GetValue("allowmultipleaddresses"), AllowMultipleAddresses); EmailSeparator = ValidationHelper.GetString(GetValue("emailseparator"), EmailSeparator); } /// /// Returns true if user control is valid. /// public override bool IsValid() { if (string.IsNullOrEmpty(txtEmailInput.Text.Trim())) { return true; } // Check if valid e-mail addresses were entered bool validEmails = (AllowMultipleAddresses ? ValidationHelper.AreEmails(txtEmailInput.Text.Trim(), EmailSeparator) : ValidationHelper.IsEmail(txtEmailInput.Text.Trim())); if (validEmails) { if (FieldInfo != null) { // Check regular expresion if (!string.IsNullOrEmpty(FieldInfo.RegularExpression)) { if (new Validator().IsRegularExp(txtEmailInput.Text.Trim(), FieldInfo.RegularExpression, "error").Result == "error") { ValidationError = FieldInfo.ValidationErrorMessage; return false; } } // Check min lenght if ((FieldInfo.MinStringLength > 0) && (txtEmailInput.Text.Trim().Length < FieldInfo.MinStringLength)) { ValidationError = FieldInfo.ValidationErrorMessage; return false; } // Check max lenght if ((FieldInfo.MaxStringLength > 0) && (txtEmailInput.Text.Length > FieldInfo.MaxStringLength)) { ValidationError = FieldInfo.ValidationErrorMessage; return false; } } return true; } else { ValidationError = GetString("EmailInput.ValidationError"); return false; } } #endregion }