Professional Web Applications Themes

javascript regular expression error - Macromedia Dreamweaver

It works here but it's not fool proof. You didn't say why it isn't working for you. It could be that your putting in odd characters in the field or it could be the way your actually calling the function. A more accurate expression ( if only numbers are truly allowed ) would be this one. /^[0-9]*$/ ....This will look for numbers only. Then in the if statement place an explanation mark before the condition stating that it is ( if not true ) instead of ( if it is true )...in other words ... if there are no numbers, ...

  1. #1

    Default Re: javascript regular expression error

    It works here but it's not fool proof. You didn't say why it isn't working
    for you. It could be that your putting in odd characters in the field or it
    could be the way your actually calling the function.

    A more accurate expression ( if only numbers are truly allowed ) would be
    this one.

    /^[0-9]*$/

    ....This will look for numbers only.

    Then in the if statement place an explanation mark before the condition
    stating that it is ( if not true ) instead of ( if it is true )...in other
    words ... if there are no numbers, or if there is anything else than a
    number even if some numbers are present.

    if (!field.value.match(/^[0-9]*$/)){

    --
    ..Trent Pastrana
    [url]www.fourlevel.com[/url]




    "Dwayne Epps" <dwayneeppscenturytel.net> wrote in message
    news:bevat4$h2$1forums.macromedia.com...
    > I am trying to create a function that checks for only numbers within a
    text
    > field. Here is the function I'm using:
    >
    > function noLetters(field) {
    > if (field.value.match(/^[a-zA-Z]*$/)) {
    > alert('This field can only contain numbers.');
    > field.focus();
    > field.select();
    > return false;
    > }
    > return true;
    > }
    >
    > It is not working and I believe the error in the syntax is within the
    line:
    > if (field.value.match(/^[a-zA-Z]*$/))
    >
    > If anyone can identify the problem with the syntax it would be
    appreciated?
    > Thanks in advance.
    > -D-
    >
    >

    T. Pastrana Guest

  2. #2

    Default Re: javascript regular expression error

    Hi Trent,
    That worked great! I appreciate the help. If I could ask one more
    question. I know there is a way to include individual characters within a
    regular expression. For example, the following statement will find any
    character
    that doesn't match with all lowercase letters, uppercase letters and digits.
    How can I also add individual characters to the expression? I would like to
    include the whitespace character for a blank space and some other additional
    characters like the comma sign, etc. within the expression.

    if (!field.value.match(/^[a-zA-Z-0-9]*$/))

    Thanks again for your help!
    -D-




    "T. Pastrana" <tpastranaNOSPAMMfourlevel.com> wrote in message
    news:bevjt9$c9d$1forums.macromedia.com...
    > It works here but it's not fool proof. You didn't say why it isn't working
    > for you. It could be that your putting in odd characters in the field or
    it
    > could be the way your actually calling the function.
    >
    > A more accurate expression ( if only numbers are truly allowed ) would be
    > this one.
    >
    > /^[0-9]*$/
    >
    > ...This will look for numbers only.
    >
    > Then in the if statement place an explanation mark before the condition
    > stating that it is ( if not true ) instead of ( if it is true )...in other
    > words ... if there are no numbers, or if there is anything else than a
    > number even if some numbers are present.
    >
    > if (!field.value.match(/^[0-9]*$/)){
    >
    > --
    > ..Trent Pastrana
    > [url]www.fourlevel.com[/url]
    >
    >
    >
    >
    > "Dwayne Epps" <dwayneeppscenturytel.net> wrote in message
    > news:bevat4$h2$1forums.macromedia.com...
    > > I am trying to create a function that checks for only numbers within a
    > text
    > > field. Here is the function I'm using:
    > >
    > > function noLetters(field) {
    > > if (field.value.match(/^[a-zA-Z]*$/)) {
    > > alert('This field can only contain numbers.');
    > > field.focus();
    > > field.select();
    > > return false;
    > > }
    > > return true;
    > > }
    > >
    > > It is not working and I believe the error in the syntax is within the
    > line:
    > > if (field.value.match(/^[a-zA-Z]*$/))
    > >
    > > If anyone can identify the problem with the syntax it would be
    > appreciated?
    > > Thanks in advance.
    > > -D-
    > >
    > >
    >
    >

    Dwayne Epps Guest

  3. #3

    Default Re: javascript regular expression error

    Dwayne,

    Well, you can add the characters you want to the character set you have
    defined in the expression. The current set contains numbers only. Just add
    the characters you wish to allow at the end.

    For example.. what was previously this ... [0-9]

    now become this... [0-9\s,.]

    The \s allows for spaces.
    The , allows for commas.
    The . allows for peroids.
    etc...

    So if you wanted to add say a colon to the equation above just add it in
    there at the end.

    and it would look like this... [0-9\s,.:]


    --
    ..Trent Pastrana
    [url]www.fourlevel.com[/url]




    "Dwayne Epps" <dwayneeppscenturytel.net> wrote in message
    news:bf26ju$mse$1forums.macromedia.com...
    > Hi Trent,
    > That worked great! I appreciate the help. If I could ask one more
    > question. I know there is a way to include individual characters within a
    > regular expression. For example, the following statement will find any
    > character
    > that doesn't match with all lowercase letters, uppercase letters and
    digits.
    > How can I also add individual characters to the expression? I would like
    to
    > include the whitespace character for a blank space and some other
    additional
    > characters like the comma sign, etc. within the expression.
    >
    > if (!field.value.match(/^[a-zA-Z-0-9]*$/))
    >
    > Thanks again for your help!
    > -D-


    T. Pastrana Guest

  4. #4

    Default Re: javascript regular expression error

    Good one... ;-)


    --
    ..Trent Pastrana
    [url]www.fourlevel.com[/url]




    "David Powers" <methisisntmyaddress.com> wrote in message
    news:bf3876$8ov$1forums.macromedia.com...
    > T. Pastrana wrote:
    > ::
    > :: /^[0-9]*$/
    > ::
    > :: ...This will look for numbers only.
    >
    > It will also match a blank field. The * means match zero or more. To
    ensure
    > at least one number is included /^[0-9]+$/
    >
    >
    > --
    > David Powers
    > *******************************************
    > No-nonsense reviews of computer books
    > [url]http://japan-interface.co.uk/webdesign/books.html[/url]
    > Save 10% on TopStyle CSS Editor
    > *******************************************
    >
    >

    T. Pastrana Guest

Similar Threads

  1. JavaScript? Putting a variable in the midst of a Regular Expression.
    By Garrett_Cobarr@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 2
    Last Post: August 8th, 09:39 PM
  2. Regular Expression Help please
    By Max Adams in forum PERL Miscellaneous
    Replies: 1
    Last Post: August 29th, 11:13 AM
  3. Regular Expression Error
    By DjDrakk in forum PHP Development
    Replies: 5
    Last Post: August 17th, 10:24 PM
  4. help with regular expression
    By gnet in forum PERL Miscellaneous
    Replies: 4
    Last Post: August 8th, 05:06 PM
  5. [PHP] REGULAR EXPRESSION HELP
    By John W. Holmes in forum PHP Development
    Replies: 3
    Last Post: July 14th, 01:23 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139