Ask a Question related to Macromedia Dreamweaver, Design and Development.
-
T. Pastrana #1
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" <dwayneepps@centurytel.net> wrote in message
news:bevat4$h2$1@forums.macromedia.com...text> I am trying to create a function that checks for only numbers within aline:> 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 theappreciated?> if (field.value.match(/^[a-zA-Z]*$/))
>
> If anyone can identify the problem with the syntax it would be> Thanks in advance.
> -D-
>
>
T. Pastrana Guest
-
Regular Expression
Hi, I am writing a script that parses an html file (which has been retrieved as a scalar by LWP::UserAgent). The script looks for everything in... -
Regular expression help
Hi, I'm pretty new to regular expressions. Before, I used to write long-winded and buggy segments of code with PHPs string functions to extract... -
Regular Expression - Need Help
Hi, I have the following: <cfset input =" Origin: cohnok-530a (190.068.59.250) Type: ... -
JavaScript? Putting a variable in the midst of a Regular Expression.
I was reading a great article by Kas Thomas, "Save Yourself Some Typing with 'With'" at PlanetPDF. I really don't care much for the term guru, I... -
Regular Expression Error
I want to use headers to redirect the client if they didn't come from the correct page, but I have a problem with one page. If they leave a form... -
Dwayne Epps #2
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" <tpastrana@NOSPAMMfourlevel.com> wrote in message
news:bevjt9$c9d$1@forums.macromedia.com...it> 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> 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" <dwayneepps@centurytel.net> wrote in message
> news:bevat4$h2$1@forums.macromedia.com...> text> > I am trying to create a function that checks for only numbers within a> line:> > 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> appreciated?> > if (field.value.match(/^[a-zA-Z]*$/))
> >
> > If anyone can identify the problem with the syntax it would be>> > Thanks in advance.
> > -D-
> >
> >
>
Dwayne Epps Guest
-
T. Pastrana #3
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" <dwayneepps@centurytel.net> wrote in message
news:bf26ju$mse$1@forums.macromedia.com...digits.> 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 andto> How can I also add individual characters to the expression? I would likeadditional> include the whitespace character for a blank space and some other> 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
-
T. Pastrana #4
Re: javascript regular expression error
Good one... ;-)
--
..Trent Pastrana
[url]www.fourlevel.com[/url]
"David Powers" <me@thisisntmyaddress.com> wrote in message
news:bf3876$8ov$1@forums.macromedia.com...ensure> 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> 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



Reply With Quote

