473,386 Members | 1,796 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.

check input data is numeric or character

idsanjeev
241 100+
how can check the input data is character or numeric if input data accept the numeric and input data is character then error message
Dec 4 '07 #1
8 28107
mzmishra
390 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. function isNumber (InString)  {
  2.     if(InString.length==0) return (false);
  3.     var RefString="1234567890";
  4.     for (Count=0; Count < InString.length; Count++)  {
  5.         TempChar= InString.substring (Count, Count+1);
  6.         if (RefString.indexOf (TempChar, 0)==-1)  
  7.             return (false);
  8.     }
  9.     return (true);
  10. }
Dec 4 '07 #2
gits
5,390 Expert Mod 4TB
hi ...

you may simply use javascripts isNaN method or a regExp ... i assume you don't want decimal input? so the shortest way is the regExp:

Expand|Select|Wrap|Line Numbers
  1. function chk_val(val) {
  2.     return /^\d+$/.test(val);
  3. }
  4.  
kind regards
Dec 4 '07 #3
idsanjeev
241 100+
i wants to input type accept numeric field if character is entered then alert message you can enter only employee number
Expand|Select|Wrap|Line Numbers
  1. <script language="Javascript">
  2. function gofirst()
  3. {
  4.   window.location = "brvoice.asp"
  5. }
  6. function chk_val(val) {
  7.     return /^\d+$/.test(val);
  8. }
  9. </script>
  10. <body background="back2.gif">
  11. <form name="myform" method="POST" action="login.asp">
  12. <div style="Position:Absolute; top:150; left:275">
  13. <center><h2><font face="arial">Welcome To Login Page</font></h2>
  14. </center>
  15. <table border = '0' align = 'center' width = '500' height = '70'>
  16.   <tr>
  17.     <td  align=right>&nbsp;&nbsp;&nbsp;<font face=Arial size=4><b>User ID</b></font></td>
  18.     <td >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type= 'text' name="empno"  onBlur="chk_val()"></td>
  19.   </tr>
  20.   <tr>
  21.     <td align=right>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font face=Arial size=4 ><b>Password</font></b></td>
  22.     <td >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type= "password" name= "password"></td></font>
  23.   </tr>
  24. </table>
  25. <table style="Position:relative; top:20; left:225"> 
  26. <tr>
  27. </td><td align='center'><input type="submit" name="submit" value="Login" ></td>
  28. <td align="right"><input type="button" name="Close" value="Close" onclick="window.close()"></tr>
  29. </table>
  30.  
Dec 4 '07 #4
gits
5,390 Expert Mod 4TB
hi ...

simply adapt it:

Expand|Select|Wrap|Line Numbers
  1. function chk_val(val) {
  2.     var chk = /^\d+$/.test(val);
  3.  
  4.     if (!chk) {
  5.         alert('please input numbers only');
  6.     }
  7. }
  8.  
kind regards
Dec 4 '07 #5
idsanjeev
241 100+
i wants to if display alert message only when character field is entered and not goes in password input if alert message is display its still in input employee no
Dec 4 '07 #6
gits
5,390 Expert Mod 4TB
Expand|Select|Wrap|Line Numbers
  1. function chk_val(obj) {
  2.     var chk = /^\d+$/.test(obj.value);
  3.  
  4.     if (!chk) {
  5.         alert('please input numbers only');
  6.         obj.focus();
  7.     }
  8. }
later on in your html put this:

[HTML]<input type="text" name="empno" onblur="chk_val(this);">[/HTML]
kind regards
Dec 4 '07 #7
idsanjeev
241 100+
Thanks i got it
Dec 6 '07 #8
gits
5,390 Expert Mod 4TB
glad to hear that ... post back to the forum anytime you have more questions

kind regards
Dec 6 '07 #9

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

Similar topics

3
by: Trevor.Dhu | last post by:
I am just starting to use python, and as such my question may well be a bit simplistic. I am currently trying to write what should be a very basic set of routines for reading and writing to a...
2
by: Dknight | last post by:
Hi, all! I have a problem, how can I check a form data before sending it to server. I have the example below, but first data is sent to server, but after JavaScript checks the data :( I need...
2
by: Jim B | last post by:
I am new to VB.NET and have a question on validating user input from a Text Box. I'm writing a small program where I want to check the users input data and determine if it's an Integer or a...
10
by: bluethunder | last post by:
I created a system and I have a problem regarding the data that will be inputted. Example the required data to be inputted is character only and another thing if the required data to be inputted is...
4
by: jane007 | last post by:
Hello everybody: I am having a problem. On Unix platform, there is a script that need user to input data from console, then when I call Unix perl script from Windows, these is an issue occurs,...
6
by: stefaniefauconnier | last post by:
I've got some html-files with a lot of greek characters in utf-8. When I open my source code, I don't see the numeric character reference but the character itself. How can I change this? I really...
1
idsanjeev
by: idsanjeev | last post by:
how can check the input data is character or numeric if input data accept the numeric and input data is character then error message
0
by: William Heymann | last post by:
How do I decode a string back to useful unicode that has xml numeric character references in it? Things like 占
3
by: Echidna | last post by:
Hi All, Wondering if anyone has encountered this one, and if anyone has a solution (or an insight into what's going wrong) This has been bugging us now for quite a while, and cannot find a...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.