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

Help with Simple validation javascript

Ok below is my javascript code that gets activated when the used changed the input text box it doesnt work before what im searching is wrong can someone help me please. for address i need it so that it will allow the street number and then one or more words after and for the credit card type i need it to have one or more words with a space inbetween thanks

Expand|Select|Wrap|Line Numbers
  1. //event handler for address
  2. function chkAddress() {
  3.     var myAddress = document.getElementById("inputtext5");
  4.  
  5. // Test the format of the input address
  6.     var pos = myAddress.value.search(/^\d+\s[A-Z][a-z]+/);  
  7.     if (pos != 0) {
  8.         alert("The name you entered (" + myAddress.value + ") is not the correct form. \n" +
  9.               "The correct form is: 15 bogus street \n" +
  10.               "Please go back and fix your Address");
  11.         myAddress.focus();
  12.         myAddress.select();
  13.         return false;
  14.     }    else
  15.         return true;
  16. }
  17.  
  18. //event handler for creditcard
  19. function chkCreditCardType() {
  20.     var myCreditCardType = document.getElementById("inputtext6");
  21.  
  22. // Test the format of the input credit card
  23.     var pos = myCreditCardType.value.search(/^w+( w+)?$/);
  24.     if (pos != 0) {
  25.         alert("The name you entered (" + myCreditCardType.value + ") is not the correct form. \n" +
  26.               "The correct form is: Master Card or Visa etc \n" +
  27.               "Please go back and fix your Credit card");
  28.         myCreditCardType.focus();
  29.         myCreditCardType.select();
  30.         return false;
  31.     }    else
  32.         return true;
  33. }
May 10 '10 #1
2 1117
RamananKalirajan
608 512MB
Whether the function is getting called? and in the html input box how you are calling the function chkAddress()?

Thanks and Regards
Ramanan Kalirajan
May 11 '10 #2
calling isnt the problem because at the moment no matter what it just runs the alert but yes it cans run from the html from and excuted in a js file
May 11 '10 #3

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

Similar topics

2
by: not | last post by:
Hello All, I am trying to develop a relatively simple self-quiz form in javascript, but I'm having no luck getting it to work. What I am looking for is a script that allow the user to select...
3
by: Marc Llenas | last post by:
Hi there, I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas? The function being called is: <script...
2
by: megabyte | last post by:
Hello; I have an ASP application which gathers information to put in a database via some forms - I would like to do the form validation (making sure some fields are not empty) with a Javascript...
2
by: Fourge | last post by:
Hi, I have run into a very strange scenario. In developing an ASP.NET application on framework version 1.1, I found that certain client-side validation scripts were not being rendered. The...
8
by: Abul Hasan | last post by:
Hello everyone, I have placed simple validation through ErrorProvider Class on my textBoxes to check whether ther r empty or not Error Provider Class check and catches the error but it doesn't...
6
by: serge calderara | last post by:
Dear all, I have read that ASP.NET does double user input validation of control when they are place on the page. Once on teh client side and again from server side right ? Could explain how...
1
by: avp | last post by:
Hi, We have an ASP.NET 2.0 (C#) application that has a web form with a CheckBoxList control and a CustomValidator control. The CustomValidator control is used to validate that at least one...
0
by: IrishDudeInUSA | last post by:
Greetings, I am trying to track a fix for the asp.net 2.0 javascript validation bug where if you are using validation controls a javascript error occurs in Internet Explorer 6.0. I was wondering...
2
by: Chad Lupkes | last post by:
Hi everyone, I need help with a simple form validation. The form I'm using has been the target of some spammers, and I'm wondering what else I can do. I have a very simple validation, checking...
9
hgeithus
by: hgeithus | last post by:
Hi. I'm doing a form at my website, and I found this document which is very interesting: Javascript form validation - doing it right . I have a little question though. All the documents within my...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.