none
regex to accept all character expect the black cerle=“&#9679” RRS feed

  • Question

  • plz help me to resolve this urgent problem .

    i have a passwordfor in asp mvc4 , and i want a regex or o javascript code to validate all character in this input expect this word "“&#9679".

    Regards .

    Friday, April 24, 2015 8:33 AM

Answers

  • It is probably easier to use just string.Contains in C# or indexOf in JavaScript. But since you need a Regular Expression for MVC validation, then try this experiment:

        string password = "My●test";

        bool is_good = Regex.IsMatch( password, "^[^\u25CF]+$" );

    I think that the expression can be specified in the corresponding validation attributes of your model.

    In JavaScript try this:

        var is_good = /^[^\u25CF]+$/.test(password);

    Monday, April 27, 2015 5:20 PM
  • Hello OPEN Hm,

    >>i have a passwordfor in asp mvc4 , and i want a regex or o javascript code to validate all character in this input expect this word "“&#9679".

    From your description, what I understand is that you are trying to validate if the input is this word "“&#9679", if so, then you may tell user this is invalid or some others.

    For this you could check this code I made below:

    List<string> excludestring = new List<string> { "“&#9679", "dsadsa" };
    
                    string pattern = @"“&#9679";
    
                    foreach (string s in excludestring)
    
                    {
    
                        Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
    
                        if (rgx.IsMatch(s))
    
                        {
    
                            Console.WriteLine("{0} is found", s);
    
                            //do your validation related stuff here
    
                        }
    
    
                    }
    

    If I do not understand correctly, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 27, 2015 4:42 AM
    Moderator

All replies

  • Hello OPEN Hm,

    >>i have a passwordfor in asp mvc4 , and i want a regex or o javascript code to validate all character in this input expect this word "“&#9679".

    From your description, what I understand is that you are trying to validate if the input is this word "“&#9679", if so, then you may tell user this is invalid or some others.

    For this you could check this code I made below:

    List<string> excludestring = new List<string> { "“&#9679", "dsadsa" };
    
                    string pattern = @"“&#9679";
    
                    foreach (string s in excludestring)
    
                    {
    
                        Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
    
                        if (rgx.IsMatch(s))
    
                        {
    
                            Console.WriteLine("{0} is found", s);
    
                            //do your validation related stuff here
    
                        }
    
    
                    }
    

    If I do not understand correctly, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 27, 2015 4:42 AM
    Moderator
  • It is probably easier to use just string.Contains in C# or indexOf in JavaScript. But since you need a Regular Expression for MVC validation, then try this experiment:

        string password = "My●test";

        bool is_good = Regex.IsMatch( password, "^[^\u25CF]+$" );

    I think that the expression can be specified in the corresponding validation attributes of your model.

    In JavaScript try this:

        var is_good = /^[^\u25CF]+$/.test(password);

    Monday, April 27, 2015 5:20 PM