[JavaScript] Problem with Regular Expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • viki1967
    Contributor
    • Oct 2007
    • 263

    [JavaScript] Problem with Regular Expression

    [Javascript] Problem with Regular Expression

    Hi all,

    First of all I must say that I am a newbie when it comes to javascript language.
    Here is my problem.

    I need validate in `myForm` this string:
    Code:
    09 - AB800
    And try this Regular Expression:
    Code:
    if (!myForm.Folder.value.match("/^0[0-9] \- [a-z0-9]{5,20}$/i", "")) {
         window.alert('Not valid.');
         myForm.Folder.focus();
         myForm.Folder.select();
         return false;
         }
    But the correct string:
    Code:
    09 - AB800
    is not validate. Why?

    I need also optional add this other string:
    Code:
    09 - AB800/test
    when the string part `/test` is not required.

    Can you explain any one or any sample code related this...

    Your help would be very appreciated.
    thanks for your time and hints.

    Thanks in advance.
    Cheers
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the main problem is that .match() expects a RegExp object to be given, not two strings.

    Comment

    • viki1967
      Contributor
      • Oct 2007
      • 263

      #3
      Hello.
      I'd appreciate your help so very much.

      What is your suggestion?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        pass a RegExp object.

        Comment

        • viki1967
          Contributor
          • Oct 2007
          • 263

          #5
          Thanks you very much for your help
          I'm really happy for your quickly answer.
          Good bye

          Comment

          Working...