Note that there are some explanatory texts on larger screens.

plurals
  1. PORegular Expression in MVC of c# to match characters
    primarykey
    data
    text
    <p>I am using a regular expression to match some characters like <code>ç"·$%&amp;/()=?</code>, etc.</p> <p>I am testing the regular expression in the web page </p> <pre><code>http://www.softlion.com/webTools/RegExpTest/default.aspx </code></pre> <p>and it is working but when I use the regular expression in my model of MVC it is not working and always I display the message of error. </p> <p>The instruction used in c# is:</p> <pre><code>[RegularExpression(@"[ç\"·$%&amp;/()=?]$", ErrorMessage="some message")] </code></pre> <p>ç\"·$%&amp;/()=?]$ are disallowed characters</p> <p>I still have the problem, and I don't understand why it is not working</p> <p>I always see the error message if I write something like: <code>ABCDEF</code> (for me it is the right characters) or <code>ABCDçEF=GHIJ</code> (incorrect)</p> <p>In the model I changed RegularExpression like a Custom Attribute. In the property of the model I have:</p> <p>[CaracteresNoPermitidosAttribute(ErrorMessage="test 123")] public string RazonSocial { get; set; }</p> <p>And the Attribute class is:</p> <pre><code>public class CaracteresNoPermitidosAttribute : RegularExpressionAttribute { public CaracteresNoPermitidosAttribute() : base(GetRegex()) { } private static string GetRegex() { // I take the data from the table to get the disallowed characters var lista = (List&lt;Caracterko&gt;) new CaracterkoProxy().ObtenerTodos(); // I transform the list to string var str = string.Join("", from x in lista where x.Activo select x.Caracter.ToString()); return @"(?![" + str + "])$"; } } </code></pre> <p>I used the example gave by Tim as regular expression</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload