473,325 Members | 2,342 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,325 software developers and data experts.

how to take either String or numbers..in txtbox

149 100+
hi,
in my project...in one of the textbox...i need to take either numbersnumbers or NULL..im not getting any idea..can anyone help me out..here is my jsp code and js code..

login.jsp

Expand|Select|Wrap|Line Numbers
  1.  
  2.  <td><font color="#800000" size=""><b>L-Acct. No.</b></font></td>
  3.                         <td><input type="text" name="localAccNo" value=NULL></td>
  4.  
login.js

Expand|Select|Wrap|Line Numbers
  1. if (document.frm.localAccNo.value == "")
  2.     {
  3.         alert("Enter Local A/c No. or 'NULL' in capitals");
  4.         document.frm.localAccNo.focus();
  5.         return (false);
  6.     }
  7.     var chkLocalAccNo = "0123456789";
  8.     var chkLocalAccNoStr = document.frm.localAccNo.value;
  9.     var allchkLocalAccNoValid = true;
  10.     for (i = 0;  i < chkLocalAccNoStr.length;  i++)
  11.     {
  12.         ch = chkLocalAccNoStr.charAt(i);
  13.         for (j = 0;  j < chkLocalAccNo.length;  j++)
  14.             if (ch == chkLocalAccNo.charAt(j))
  15.                 break;
  16.         if (j == chkLocalAccNo.length)
  17.         {
  18.             allchkLocalAccNoValid = false;
  19.             break;
  20.         }
  21.     }
  22.     if (!allchkLocalAccNoValid)
  23.     {
  24.         alert("Enter only numeric in the \" Local A/c No. \" field");
  25.         document.frm.localAccNo.focus();
  26.         return (false);
  27.     }
  28.  
thanks,
madhu.
Jul 16 '10 #1
33 1604
Dormilich
8,658 Expert Mod 8TB
I don’t understand your checking logic. you can test, whether an input qualifies for a number with either isFinite() or isNaN() (parseInt() would be a good starting point either, even RegExp were possible) and how to test for "NULL" I hopefully don’t have to explain.
Jul 16 '10 #2
madhuriks
149 100+
hi,
i checked with the values..if i had given 'NULL' it is taking and if i give 'NULL123' is also taking...but i need is it should take either numbers or NULL that means

L-Acct. No.----> NULL
or
L-Acct. No.----> 123


like this i need i used RegExp..eventhough im not getting can u suggest me how to do..
Jul 16 '10 #3
Dormilich
8,658 Expert Mod 8TB
how familiar are you with RegExp?
Jul 16 '10 #4
madhuriks
149 100+
i m not that much familiar..im a learner

i used like this

Expand|Select|Wrap|Line Numbers
  1.  
  2. if (document.frm.localAccNo.value == "")
  3.     {
  4.         alert("Enter Local A/c No. or 'NULL' in capitals");
  5.         document.frm.localAccNo.focus();
  6.         return (false);
  7.     }
  8.     var chkLocalAccNo = "[NULL/0123456] ";
  9.     var chkLocalAccNoStr = document.frm.localAccNo.value;
  10.     var allchkLocalAccNoValid = true;
  11.     for (i = 0;  i < chkLocalAccNoStr.length;  i++)
  12.     {
  13.         ch = chkLocalAccNoStr.charAt(i);
  14.         for (j = 0;  j < chkLocalAccNo.length;  j++)
  15.             if (ch == chkLocalAccNo.charAt(j))
  16.                 break;
  17.         if (j == chkLocalAccNo.length)
  18.         {
  19.             allchkLocalAccNoValid = false;
  20.             break;
  21.         }
  22.     }
  23.     if (!allchkLocalAccNoValid)
  24.     {
  25.         alert("Enter only numeric in the \" Local A/c No. \" field");
  26.         document.frm.localAccNo.focus();
  27.         return (false);
  28.     }
  29.  
Jul 16 '10 #5
Dormilich
8,658 Expert Mod 8TB
no wonder that NULL123 worked …

ok, part one: how would you (in the simplest way) test for the string "NULL"?
Jul 16 '10 #6
madhuriks
149 100+
Expand|Select|Wrap|Line Numbers
  1. if(document.frm.localAccNo.value == null){
  2. alert(' null');
  3. }else if(document.frm.localAccNo.value == 'null'){
  4. alert('value is a string null');
  5.  
  6.  
Jul 16 '10 #7
Dormilich
8,658 Expert Mod 8TB
looks good, but
- line 1/2 would also fire for "" (empty string).
- line 3/4 would not fire for "NULL" (or any version with capital letters)

tip: save the field’s value in a variable, that’s saving you (and the script) a massive amount of time.
Jul 16 '10 #8
madhuriks
149 100+
i hope isNan() function should be used for this
Jul 16 '10 #9
Dormilich
8,658 Expert Mod 8TB
isNan() would throw an error (because the function is called isNaN()), but it depends for what you need isNaN(). (as I already mentioned, isNaN() is one way to test a part of your requirements)
Jul 16 '10 #10
madhuriks
149 100+
i didnt got ur point...can u help me how?
Jul 16 '10 #11
Dormilich
8,658 Expert Mod 8TB
what will you use isNaN() for? there are codes, where isNaN() would definitely help, and codes where it were absolutely pointless.
Jul 16 '10 #12
madhuriks
149 100+
hi,
gud mrng..i tried..its getting but the problem is if i enter 'NULL123' it is not showing error..can u suggest me where to change the code..here is my code..

login.js

Expand|Select|Wrap|Line Numbers
  1.  var chkLocalAccNo = document.frm.localAccNo.value;
  2.     //check if it is not a number
  3.     var validation = true;
  4.     for (var i = 0; i < chkLocalAccNo.length; i++ )
  5.     {
  6.         if (isNaN(chkLocalAccNo.charAt(i)))
  7.         {
  8.             //if it is not a number check if it is NULL
  9.             if (chkLocalAccNo == 'NULL')
  10.             {
  11.                 validation = true;
  12.                 document.frm.localAccNo.focus();
  13.             }
  14.             else
  15.             {
  16.                 validation = false;
  17.                 document.frm.localAccNo.focus();
  18.             }
  19.         }
  20.     }
  21.  
  22.  
thanx and waiting for the reply.
madhu.
Jul 19 '10 #13
Dormilich
8,658 Expert Mod 8TB
discard the loop.
Jul 19 '10 #14
madhuriks
149 100+
i discard for loop eventhough it is not getting..
Jul 19 '10 #15
Dormilich
8,658 Expert Mod 8TB
what does your code looks like now?
Jul 19 '10 #16
madhuriks
149 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2. if (document.frm.localAccNo.value == "")
  3.     {
  4.         alert("Enter Local A/c No. or 'NULL' in capitals");
  5.         document.frm.localAccNo.focus();
  6.         return (false);
  7.     }
  8.  
  9.     var chkLocalAccNo = document.frm.localAccNo.value;
  10.     //check if it is not a number
  11.     var validation = true;
  12.     if (isNaN(chkLocalAccNo.charAt(i)))
  13.         {
  14.             //if it is not a number check if it is NULL
  15.             if (chkLocalAccNo == 'NULL')
  16.             {
  17.                 validation = true;
  18.                 document.frm.localAccNo.focus();
  19.             }
  20.             else
  21.             {
  22.                 validation = false;
  23.                 document.frm.localAccNo.focus();
  24.             }
  25.         }
  26.  
  27.      alert('Validation is: ' + validation);
  28.  
  29.  
if i give 'NULL' it is showing 'Valid' and going to another page same for nos. also..but if i give 'NULL123' it is showing 'Validation false' and it is going to another page by clicking submit button..but i should not get like that..
Jul 19 '10 #17
Dormilich
8,658 Expert Mod 8TB
see line 12? esp. the charAt(i) portion?
Jul 19 '10 #18
madhuriks
149 100+
i deleted and checked now same problem i m getting it is taking 'NULL123'...but not throwing error..
Jul 19 '10 #19
Dormilich
8,658 Expert Mod 8TB
I can imagine why, but I’m not sure until I see the working code.
Jul 19 '10 #20
madhuriks
149 100+
k,here is my code..

login.jsp

Expand|Select|Wrap|Line Numbers
  1. <td></td>
  2.                         <td><font color="#800000" size=""><b>L-Acct. No.</b></font></td>
  3.                         <td><input type="text" name="localAccNo"></td>
  4.                         <td></td>
  5.  
login.js

Expand|Select|Wrap|Line Numbers
  1. if (document.frm.localAccNo.value == "")
  2.     {
  3.         alert("Enter Local A/c No. or 'NULL' in capitals");
  4.         document.frm.localAccNo.focus();
  5.         return (false);
  6.     }
  7.  
  8.     var chkLocalAccNo = document.frm.localAccNo.value;
  9.     //check if it is not a number
  10.     var validation = true;
  11.     if (isNaN(chkLocalAccNo))
  12.         {
  13.             //if it is not a number check if it is NULL
  14.             if (chkLocalAccNo == 'NULL')
  15.             {
  16.                 validation = true;
  17.                 document.frm.localAccNo.focus();
  18.             }
  19.             else
  20.             {
  21.                 validation = false;
  22.                 document.frm.localAccNo.focus();
  23.             }
  24.         }
  25.  
  26.      alert('Validation is: ' + validation);
  27.  
i need it urgent..where is wrong in the code..suggest me..
Jul 19 '10 #21
Dormilich
8,658 Expert Mod 8TB
where is wrong in the code
it work for me.
Jul 19 '10 #22
madhuriks
149 100+
i tried it is not getting...here is the code can u chk it.


login.js
Expand|Select|Wrap|Line Numbers
  1. function validate()
  2. {
  3. if (document.frm.multiAct.value == "")
  4.     {
  5.         alert("Enter Multiple Activation");
  6.         document.frm.multiAct.focus();
  7.         return (false);
  8.     }//Close of Multiple Activation Status
  9.  
  10.     if (document.frm.nullDa.value == "")
  11.     {
  12.         alert("Enter Null DA");
  13.         document.frm.nullDa.focus();
  14.         return (false);
  15.     }//Close of Null DA Status
  16.  
  17.     if (document.frm.localAccNo.value == "")
  18.     {
  19.         alert("Enter Local A/c No. or 'NULL' in capitals");
  20.         document.frm.localAccNo.focus();
  21.         return (false);
  22.     }
  23.  
  24.     var chkLocalAccNo = document.frm.localAccNo.value;
  25.     //check if it is not a number
  26.     var validation = true;
  27.     if (isNaN(chkLocalAccNo))
  28.         {
  29.             //if it is not a number check if it is NULL
  30.             if (chkLocalAccNo == 'NULL')
  31.             {
  32.                 validation = true;
  33.                 document.frm.localAccNo.focus();
  34.             }
  35.             else
  36.             {
  37.                 validation = false;
  38.                 document.frm.localAccNo.focus();
  39.             }
  40.         }
  41.  
  42.      alert('Validation is: ' + validation);
  43. return true;
  44. }
  45.  
  46.  
login.jsp

Expand|Select|Wrap|Line Numbers
  1.  
  2. <td></td>
  3.                         <td><font color="#800000" size=""><b>Multiple Activation</b></font></td>
  4.                         <td><input type="text" name="multiAct"></td>
  5.                         <td></td>
  6.                         <td><font color="#800000" size=""><b>Null DA</b></font></td>
  7.                         <td><input type="text" name="nullDa"></td>
  8.                         <td></td>
  9.                         <td><font color="#800000" size=""><b>L-Acct. No.</b></font></td>
  10.                         <td><input type="text" name="localAccNo"></td>
  11.                         <td></td>
  12.  
  13.  
can u chk it..with the given code
Jul 19 '10 #23
Dormilich
8,658 Expert Mod 8TB
post a link to the page, that makes it easier to check.
Jul 19 '10 #24
madhuriks
149 100+
i didnt got ur point
Jul 19 '10 #25
Dormilich
8,658 Expert Mod 8TB
if I should test your script, I need it to test with your website, as it works when I build my own test page.
Jul 19 '10 #26
Dormilich
8,658 Expert Mod 8TB
http://localhost:8080/proj/jsp/register.jsp
and now upload that to a publicly accessible webserver.
Jul 19 '10 #28
madhuriks
149 100+
that means..
Jul 19 '10 #29
Dormilich
8,658 Expert Mod 8TB
something like http://example.org/register.jsp. or have you another idea, how I shall address your computer?
Jul 19 '10 #30
madhuriks
149 100+
i m sorry i tried..but my ip address was blocked..i snded u the code u can chek it na
Jul 19 '10 #31
Dormilich
8,658 Expert Mod 8TB
now I don’t get you …
Jul 19 '10 #32
madhuriks
149 100+
my ip address was blked by my cmpny..so i cant see my ip address..i hd pasted the code na...u cn chk it..
Jul 19 '10 #33
Dormilich
8,658 Expert Mod 8TB
all you need is a personal webserver.
Jul 19 '10 #34

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

Similar topics

2
by: lkrubner | last post by:
What I need to do is find out what characters in a string are not supported by the UTF-8 encoding. The problem arises when someone logs in and uses my php script to create a weblog post. They are...
2
by: pesso | last post by:
I have a string that contains the following: string s = "130,41,43,178,41,17,6,78,244,35,202,144,115"; They are comma separated byte numbers, and I need to initialize my byte array with them....
2
by: acool | last post by:
I am passing in, as a parameter, a string of XML, and want to formulate a new XML docuent but i am getting errors. I tried this: public string makeDoc(string document) { // XmlDocument doc =...
0
by: Alan Silver | last post by:
Hello, I am writing the code-behind for a user control that may have either a Repeater or a DataList (depending on which .ascx file calls the code-behind). I have put an DataItemBound event for...
2
by: Bryan | last post by:
Apologies if this is a noob question, but I've been struggling with this for quite a while... I'm trying to convert a byte array (encrypted authorization code) into a *screen-printable* string...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
1
by: DR | last post by:
how to determine what language a c# string is written in? is there any C# method to take a string and return what language it is in? e.g. english, hindi, spanish, etc.
1
by: DR | last post by:
how to determine what language a string is written in? is there any method to take a string and return what language it is in? e.g. english, hindi, spanish, etc.
4
by: vrsoft | last post by:
i want to separate string within the specified tag. eg., <strong>some string here</strong> result should be:"some string here" pl help me.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.