View Full Version : regular expression help
02-08-2004, 09:16 PM
I have a regular expression that is searched on a field coming from a form....
It basically returns true or false and looks for ONLY numbers.. ie: It validates that the entry is only numbers, and nothing else.
I need it changing so that it will allow a period (.) and a minus (-)
here's what I have at the mo
how do I make it so that only numbers, a full stop and a minus can be entered??
thanks for any help :)
02-08-2004, 09:25 PM
I'm still struggling with regular expressions myself.
So forgive me if there is a better way.
02-08-2004, 09:42 PM
hey thanks for the fast response...
if ((ignoreWhiteSpace && string.search(/^[\-+0-9+\.]*$/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1))
but it still didnt seem to work... it wouldnt allow a "."
not really sure what I am doing!! :p
02-08-2004, 10:26 PM
As I said, I'm still struggling.
But I think you are missing either the .match or .test methods.
Here is an example of how I would use it:
var regex = /^[\-+0-9+\.]*$/;
field.value = field.value.replace(/[^\-+0-9+\.]/g,"");
<input type="text" name="firstnumber" onkeyup="isNumber(this)">
Perhaps someone who actually knows regex will soon
come along and straighten us both out. Until then....
Hope this is of some help;
02-08-2004, 10:34 PM
; /* bad */
; /*good */Though note that matching this pattern does not mean the string is a number (e.g., "-.-.-" is not a number). Instead use the isNaN function.
; /* not a number */
; /* a number */
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.