473,382 Members | 1,752 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,382 software developers and data experts.

code to find whether only numerals are entered in a text box

Hi ,


Can anybody help me with the code , to find whether only numerals are entered in a text box (using js.),at the time of saving.

jk
Jan 7 '08 #1
7 1532
chaarmann
785 Expert 512MB
Hi ,


Can anybody help me with the code , to find whether only numerals are entered in a text box (using js.),at the time of saving.

jk
Just put an onKeyUp-event and onChange-event for the text box which calls a javascript function.
Or call this function in your onSubmit() function of your form.
This javascript function, which you can put into your ".js" file, uses a regular expression that checks for digits.
If you do it this way with regExpr., then you can write the function by using only one line of source code.
Jan 7 '08 #2
gits
5,390 Expert Mod 4TB
hi ...

a regExp would do the job. in case you only want integers you may use something like the following for it:

Expand|Select|Wrap|Line Numbers
  1. // val may be you input-value
  2. var val = '123';
  3.  
  4. // function that checks for numbers - returns true when 
  5. // ok otherwise it returns false (the regExp is literally created
  6. // with /^\d+$/ and checks for numbers from start to end)
  7. function test_value(val) {
  8.     return /^\d+$/.test(val);
  9. }
  10.  
  11. // now we could call the function
  12. alert(test_value(val));
  13.  
kind regards
Jan 7 '08 #3
hi frnds,

thanx for ur fast reply! i hv done tat as u said and itz workin!!!

gitz,actually i want to check whether only integers are entered in the field and if there is notin other than integers,then i hv to reject it!I hv done tat using the code u hv given.
Then i need a thing similar to this,tat is i want to check whether only special characters are entered in a textfield?
can u help me in tat?


thanks in advace
jk
Jan 7 '08 #4
gits
5,390 Expert Mod 4TB
:) glad to hear that ... for further information you may have a look here
and may be for your next purpose you may use:

Expand|Select|Wrap|Line Numbers
  1. /^\W$/
instead of

Expand|Select|Wrap|Line Numbers
  1. /^\d$/
kind regards
Jan 7 '08 #5
Hi gits,

Thanks again ...by replacing the function as u said,itz now possible to check the existence of special characters only in a textbox.!!!

Takecare!




jk
Jan 8 '08 #6
gits
5,390 Expert Mod 4TB
hi ...

that's what you needed ... in't it :) ... post back to the forum anytime you have more questions ...

kind regards
Jan 8 '08 #7
hi ...

that's what you needed ... in't it :) ... post back to the forum anytime you have more questions ...

kind regards

hi gits,

Yes thatz exactly wat i needed! Then i ll post my queries in dis forum,when i got any problems.


WarmRegards
jk
Jan 8 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Vinod | last post by:
Hi, I have got a peculiar requirement. I want to distinquish between the color codes. I have got two text fields and i will enter the color codes there. The first text field will have ...
6
by: Mutley | last post by:
I am finding an issue with the current DropDownList and ListBox ASP.NET Web Controls. I had a system set up for Arabic and a string that I put into a drop down had a number. The letters were being...
2
by: Maellic | last post by:
Hi, I'm currently updating a website written with ASP.NET. The original programmer is overseas, there is no documentation, and files are all over the place. Here is a code snippet from one of...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
4
by: Kun | last post by:
I have the following if statement that checks if a form is empty: if form.has_key("date") and form.value != "": date=form.value else: print "ERROR: No date entered!" raise Exception I...
16
by: KIRAN | last post by:
Hi all, #include<stdio.h> int main(void) { int a = 1;
3
by: sweetamy | last post by:
i am making an html form......it should check the values before accepting the data in the database,,,,,,,,,,,,,a field name USER NAME should check if the value entered is only a character value nd...
4
by: Semajthewise | last post by:
Hi All For those of you that helped me with the questions on this... Thank you! I believe I have solved all the bugs in the code and wanted to post the final product. This is a set of code to solve...
1
by: Semajthewise | last post by:
Here it is cleaned up a little more. Here's what this code does. It will take 2 fractions and add, subtract, multiply, or divide them. The user enters the fractions to be calculated into two...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.