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 and dates.

  • 12-09-2002 8:02am
    #1
    Closed Accounts Posts: 192 ✭✭


    Hi all,
    I've been having a spot of bother with a regular expression that I need to use. I have a text field that I need to validate the correct formats are as follows
    dd/mmm/yyyy
    12/feb/2002
    ('empty')
    yes the third one is an empty string. Currently I have the first and second working but cant figure out the empty string, the regular expression i'm using is
    ([0-9d]{2}\/[A-Za-z]{3}\/[0-9y]{4})
    can anyone tell me how to check for the empty string as well
    Regards,
    Clamor.


Comments

  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Wouldn't it just be:
    ([0-9d]{2}\/[A-Za-z]{3}\/[0-9y]{4}|)
    
    (Note pipe on the end.)

    By the way, your regex will still allow anomalies, people will be able to mix and match, for example with a year like 200y.

    adam


  • Closed Accounts Posts: 192 ✭✭Clamor


    Good point.
    I'll need to tighten it a bit more.
    Adding the pipe at the end though allows everything to get through.
    I've changed the expression so it now looks like
    (^\s*$)|([0-9d]{2}\/[A-Za-z]{3}\/[0-9y]{4})
    This catches the empty string or the date format now. I still need to sort out the issue you brought up though.


  • Closed Accounts Posts: 192 ✭✭Clamor


    This should work now.
    (^\s*$)|([0-9]{2}\/[A-Za-z]{3}\/[0-9]{4})|([d]{2}\/[m]{3}\/[y]{4})
    :)


Advertisement