至少8个字符/大写/数字的模式

时间:2017-04-15 02:17:42

标签: regex symfony validation fosuserbundle

目前我正在使用symfony2,我需要一个条件模式: -min 8个字符,最多20个字符 - 至少包含1个字母 - 至少必须包含1个号码 - 可能包含特殊字符,如!@#$%^& *()_ + 我试过这段代码,但它不起作用:

/**
 * Encrypted password. Must be persisted.
 * @Assert\Regex(
 *     pattern     = "/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[?!-‌​/_/=:;§]).{8,20}+$/i",
 *     htmlPattern="/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[?!-‌​/_/=:;§]).{8,20}$/",
 *     match=true,
 *     message="message error ")
 *
 * @var string
 */
protected $password;

2 个答案:

答案 0 :(得分:0)

你试过这样的事吗?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

public partial class Index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void send_Click(object sender, EventArgs e)
    {
        string smtpAddress = "smtp.gmail.com";
        int portNumber = 587;
        bool enableSSL = true;

        string emailfrom = "example@gmail.com";
        string password = "*********";
        string subject = "Contact Form Data";
        string emailto = "example@gmail.com";
        string name = n.Value;
        string useremail = em.Value;
        string phone = tel.Value;
        string dept = dep.Value;
        string dest = des.Value;
        string adu = ad.Value;

        
        string body = "Name: " + name + " ;" + " Email: " + useremail + " ;" + "Telephone: " + phone + " ;" + " Departure Place: " + dept + " ;" + "Destination Place: " + dest + " ;" + " Adults: " + adu + " ;" + " ;" + "Children: " + chil +  " ;";

        using (MailMessage mail = new MailMessage())
        {
            mail.From = new MailAddress(emailfrom);
            mail.To.Add(emailto);
            mail.Subject = subject;
            mail.Body = body;
            mail.IsBodyHtml = true;




            using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
            {
                smtp.Credentials = new NetworkCredential(emailfrom, password);
                smtp.EnableSsl = enableSSL;
                smtp.Send(mail);
            }
        }
    }
}

答案 1 :(得分:0)

非常感谢你的回答。 我必须覆盖$plainPassword而不是$password的正则表达式,因为我正在使用FOSuserBundle。