Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Regular expression weirdness (Asp.net validator control)

  • 31-05-2007 10:54am
    #1
    Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭


    ^(?=.*[a-z].*[a-z])(?=.*[A-Z].*[A-Z])(?=.*\d.*\d)[a-zA-Z0-9]{8,}$
    

    This checks that a string is at least 8 characters long, has 2 lower case character, 2 uppercase characters and two numeric characters. The above regex seems to be valid, at least it works in code. But when I apply it to a regex validator control it fails all the time. Does anybody have an idea why its not working? Suppose I'd better include the markup for the control ...

    [html]
    <asp:TextBox ID="txtDemo" runat="server"></asp:TextBox>
    <asp:RegularExpressionValidator ID="revDemo" runat="server" ErrorMessage="Failed"
    ValidationExpression="^(?=.*[a-z].*[a-z])(?=.*[A-Z].*[A-Z])(?=.*[0-9].*[0-9])[a-zA-Z0-9]{8,}$"
    ControlToValidate="txtDemo" EnableClientScript="true"></asp:RegularExpressionValidator>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" CausesValidation="true" />
    [/html]


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 9,035 Mod ✭✭✭✭mewso


    You say it fails but you don't say in what way. Could be a script problem. Does it work with enableclientscript=false?

    i.e. when the page post back and you call page.isvalid will it correctly show the error?


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Sorry, when I say it fails I mean the validation fails.

    Setting EnableClientScript to false worked but the problem is I need the clientscript working too. Any ideas?


  • Registered Users, Registered Users 2 Posts: 437 ✭✭Spunj


    Evil Phil wrote:
    Setting EnableClientScript to false worked but the problem is I need the clientscript working too. Any ideas?

    That explains it. The RegEx works different on the client than the server. As far as I know, it uses a different syntax on the client (JScript I think). You will have to look up what's different in that syntax and modify the RegEx to match I reckon.

    edit:
    The JScript RegEx is a subset of the System.Text.RegularExpressions and its missing stuff like backreferences and other things that I forget right now. There has to be something in your RegEx thats not supported?


  • Moderators, Science, Health & Environment Moderators Posts: 9,035 Mod ✭✭✭✭mewso


    I'm up to here with Microsoft and their javascript. They haven't got a clue. i would suggest you implement your own solution.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I had a feeling it was going to be a javascript thing. I'll try getting it working and let you know how I get on.

    I'll probably just end up doing my own solution though.


  • Advertisement
Advertisement