473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Numeric field validation fails for single character

I am using following function to check for my input
my input is like 0.00 i dont want to allow any specialcharacters.

function numericValidation() {
var x = this;
var reg = new RegExp('^[0-9]*\.?[0-9]*$');

if (reg.test(x)) {
return true;
}
else return false;
}

here problem is when i type one character other than this range Regular
expression doesnt work i mean it gives true for input '@' if i type
'@@'then it gives false

actually it shd gv false for both the case.

Mar 3 '06 #1
4 3508
nk*****@gmail.com wrote:
I am using following function to check for my input
my input is like 0.00 i dont want to allow any specialcharacters.

function numericValidation() {
var x = this;
var reg = new RegExp('^[0-9]*\.?[0-9]*$');

---------------------------------------------^

When calling RegExp as a constructor, quoted special characters in the
string literal need two backslashes - you have to quote the quote to get
it past the parser (if that makes sense...). Use:

var reg = new RegExp('^[0-9]*\\.?[0-9]*$');
Note use of '\\'.
[...]
--
Rob
Mar 3 '06 #2

"RobG" <rg***@iinet.net.au> wrote in message
news:0c*****************@news.optus.net.au...
nk*****@gmail.com wrote:
I am using following function to check for my input
my input is like 0.00 i dont want to allow any specialcharacters.

function numericValidation() {
var x = this;
var reg = new RegExp('^[0-9]*\.?[0-9]*$'); ---------------------------------------------^

When calling RegExp as a constructor, quoted special characters in the
string literal need two backslashes - you have to quote the quote to get
it past the parser (if that makes sense...). Use:

var reg = new RegExp('^[0-9]*\\.?[0-9]*$');
Note use of '\\'.


Or use a regular expression literal:
var reg = /^[0-9]*\.?[0-9]*$/;

[...]
--
Rob

Mar 3 '06 #3
if i use a regular expression literal can i still use test methos with
it ?:
var reg = /^[0-9]*\.?[0-9]*$/;
Vic Sowers wrote: "RobG" <rg***@iinet.net.au> wrote in message
news:0c*****************@news.optus.net.au...
nk*****@gmail.com wrote:
I am using following function to check for my input
my input is like 0.00 i dont want to allow any specialcharacters.

function numericValidation() {
var x = this;
var reg = new RegExp('^[0-9]*\.?[0-9]*$');

---------------------------------------------^

When calling RegExp as a constructor, quoted special characters in the
string literal need two backslashes - you have to quote the quote to get
it past the parser (if that makes sense...). Use:

var reg = new RegExp('^[0-9]*\\.?[0-9]*$');
Note use of '\\'.


Or use a regular expression literal:
var reg = /^[0-9]*\.?[0-9]*$/;

[...]
--
Rob


Mar 3 '06 #4
nk*****@gmail.com wrote:
if i use a regular expression literal can i still use test methos with
it ?:
var reg = /^[0-9]*\.?[0-9]*$/;


Yes, you can. The RegExp literal creates a RegExp object. Why do you not
just try it?

You can even provide attribution of quoted material, and stop top-posting.

<URL:http://safalra.com/special/googlegroupsreply/>
PointedEars
Mar 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Hugo Coolens | last post by:
I want to order a text field which contains some words which begin with a single quote, if however I perform the following query, the single quote seems to be neglected: select arabic, dutch...
4
by: Colin Graham | last post by:
Hi there, Im very new to javascript and this is my first bit of javascript coding. I have to write a validation check for two fields that they don't contain all the same characters e.g., ...
3
by: Srinivas | last post by:
Hi If a textbox is being validated using a required field validator then we need to key in some text before sumbmitting the form. But if we key in a space character this gets validated to true...
2
by: Chad | last post by:
I have a textbox control, txtMeasurement, that I want to allow only numeric decimal input. I thought to use a client side validation control to ensure that the data entered is of type "Double". ...
1
by: Niclas | last post by:
Hi, How do I indicate what field fails a validation, usually you see a red star next to the faild field on a form. Is this built in functionality in the valdaition controls or shall I code this...
13
by: nishit.gupta | last post by:
Is their any fuction available in C++ that can determine that a string contains a numeric value. The value cabn be in hex, int, float. i.e. "1256" , "123.566" , "0xffff" Thnx
8
by: .Net Sports | last post by:
I am checking for text input on a form validation in javascript that required at least one numeric character along with any number of alpha characters for a given input text box. The below is a var...
3
by: aris1234 | last post by:
Hi.. i have field in record using type : numeric, how to make validation and i want viewing messagebox if user inputing character or empty? this code just work for empty field, not for numeric...
1
by: David Greenberg | last post by:
Hi I have a character field (char ot varchar) that I want to force only to contain numeric characters. Can that be done by way of defining a constraint on the field ? or by any other way in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.