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

how to check value entered in field

149 100+
hi,
i m new to this site as well as to Javascript.In my project i need to use javascript..in my code if i enter the textfield 'MA' it should take along with numbers...but the problem is if i enter 'MAA' it is not showing any error..the text field should take on 'MA' not 'MAA'...i used the charAt() function...i m not getting any one can help me...its urgent...here i m sending the code..waiting for the reply...

Expand|Select|Wrap|Line Numbers
  1. function pasuser(form)
  2. {
  3.     if (form.n1.value == "")
  4.     {
  5.         alert("Enter Package Name");
  6.         form.n1.focus();
  7.         return (false);
  8.     }
  9.     var chk = form.n1.value;
  10.     var chk1=chk.charAt(0);
  11.     var allValid = true;
  12.     if (chk1=="M")
  13.     {
  14.         alert("u entered correct");
  15.         form.n1.focus();
  16.         allValid = false;
  17.     }
  18.     else if (!allValid)
  19.     {
  20.         alert("Enter only M");
  21.         form.n1.focus();
  22.         return (false);
  23.     }
  24.     form.submit();
  25.     return true;
  26. }
Thanks&Regards,
madhuri.
Jun 11 '10 #1
5 2202
Dormilich
8,658 Expert Mod 8TB
do you mean that the text field should take only "MA" or MA accompanied with numbers, like "MA12345"?
Jun 11 '10 #2
madhuriks
149 100+
hi,
it should take 'MA123456789'...not 'MAA123456789'..i tried using indexOf() and charAt()...but unable to get it...can u help me out from this....

Thanks&Regards,
Madhuri.
Jun 11 '10 #3
Dormilich
8,658 Expert Mod 8TB
then I recommend that you test your string against a RegEx:
Expand|Select|Wrap|Line Numbers
  1. if (/^MA\d+$/.test(document.forms[0].n1.value) {
  2.     alert("valid");
  3. }
Jun 11 '10 #4
madhuriks
149 100+
hi,
thanks for your reply..i tried i m not getting..if i enter wrong value i.e 'nn'..it is not showing error..here with i m sending the code can u once check it..

Expand|Select|Wrap|Line Numbers
  1. function pasuser(form)
  2. {
  3.     if (form.n1.value == "")
  4.     {
  5.         alert("Enter Package Name");
  6.         form.n1.focus();
  7.         return (false);
  8.     }
  9.     if (/^MA\d+$/.test(document.forms[0].n1.value))
  10.     {
  11.          alert("valid");
  12.          form.nl.focus();
  13.          return (false);
  14.      }
  15.     form.submit();
  16.     return true;
  17. }
Thanks & Regards,
madhuri.
Jun 11 '10 #5
Dormilich
8,658 Expert Mod 8TB
this might be an addressing issue (the part before .value), because I don’t know your form setup.
Jun 11 '10 #6

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

Similar topics

8
by: Jack | last post by:
Hi, Here is my problem: I am logging in to a page, where the page retrieves a record from a database. The text boxes are used in the display formto let the users update the fields, if they...
1
by: Jim | last post by:
I have a 2 checkboxes and a hidden field..what I want to happen is that you can only click on 1 of these checkboxes at a time and when you check a checkbox it will assign the hidden field...
5
by: Wouter | last post by:
Hi, I had a javscript what does the follow. When a checkbox is yes then i will see a form field. When a checkbox is no i dont see the form field. Can somehelp me for that script ? Greets...
4
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
4
by: Andy Hutchings | last post by:
Hi everybody - hope you can help out here. I have a form in a database, which is a columnar form from one of the tables in the db - there is a sub-form to the form which is a datasheet view of...
4
by: Zenon | last post by:
I am attempting to append a string prefix to a report field which is based on a query result. I want the user to be able click a checkbox on the form which opens the report to determine whether...
2
by: LoopyNZ | last post by:
Hi, (Access 97) I'm creating a query (QRY_SUMMARY) to join a query (QRY) to itself (QRY_1). I'm returning QRY.* and selected fields from QRY_1. With each field (field_name) I return from...
1
by: VegaGucci | last post by:
Hi there, I am trying to get the value of an SQL bit field, to link it to an groupbox with 2 radiobuttons. but for some reason..the value of the bit field is NEVER 1/true code: if...
1
by: Harry Devine | last post by:
I have a DataGrid that is configured to use the Edit/Update/Cancel concept correctly. My grid shows values from 5 database fields. I only need to update that last 4 fields. The last field is a...
1
by: suchismitaswain | last post by:
Hi, I have a field in jsp page that has some textboxes. but the texboxes are dynamically created depending on the no of rows in a table. When i click the update button in my jsp page it has to get...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
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
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...

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.