星期五, 3月 17, 2006

[.Net]Regular expression in common use

Because of my private project, I surfed on internet for these regular expression. These regular expression will be used in RegularExpressionValidator.
  • Validate Date
    • dd/mm/yyyy
      ((([0][1-9]|[12][\d])|[3][01])[-/]([0][13578]|[1][02])[-/][1-9]\d\d\d)|((([0][1-9]|[12][\d])|[3][0])[-/]([0][13456789]|[1][012])[-/][1-9]\d\d\d)|(([0][1-9]|[12][\d])[-/][0][2][-/][1-9]\d([02468][048]|[13579][26]))|(([0][1-9]|[12][0-8])[-/][0][2][-/][1-9]\d\d\d)
    • yyyy/mm/dd
      ([1-9]\d\d\d[-/]([0][13578]|[1][02])[-/](([0][1-9]|[12][\d])|[3][01]))|([1-9]\d\d\d)[-/]([0][13456789]|[1][012])[-/](([0][1-9]|[12][\d])|[3][0])|([1-9]\d([02468][048]|[13579][26])[-/][0][2][-/]([0][1-9]|[12][\d]))|([1-9]\d\d\d[-/][0][2][-/]([0][1-9]|[12][0-8]))
  • The number with limited digits
    (^-?\d{1,10}\.$)|(^-?\d{1,10}$)|(^-?\d{0,10}\.\d{1,9}$)
  • Number
    ^(-)?\d+(\.\d\d)?$
  • Validate e-mail
    ^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
  • Validate url
    ^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$


Reference:

沒有留言: