JAVA SCRIPT HELP II

maxXxa

Member
Apr 14, 2010
341
5
0
Write Javascript code to validate a registration number of a vehicle. The code
has to be able to accept the registration number as a string, checks whether th
format is valid and displays the province that the vehicle has been registered
by reading the two alpha characters at the beginning. (as given in Figure 1)

Example: valid format - CPNA-8130 - (four characters - four digits) Centra
Province.


function validate(){

var valid = false;
var v = document.getElementById("regNo").value;
if(!(v== "")@@ (v.length < 9)) {
alert("Please Enter Registration Number");
valid = false;
}
else
{
var a = v.split("-");
var pro = a.substring(0,2);

if(pro=="cp"){
alert("Central Province");
valid = true;
}
if(pro=="wp"){
alert("Western Province");
valid = true;
}
}

mage answer eka poddak hari shape da ..?? plzz help ekak denawada ...
thnkuu:)
 
Last edited:

vidura99

Well-known member
  • Oct 16, 2009
    14,306
    1,361
    113
    Colombo
    if(!(v== "")@@ (v.length < 9))

    wada karanna widiyak nae ne ban.
    eka
    if(!(v== "")|| (v.length < 9)) kiyala change karanna ona nadda??
     

    viraj_slk

    Active member
  • Oct 1, 2007
    505
    35
    28
    bro, you have taken a good effort to solve this one. good work. keep improving your answer to get better results.

    if((v== "")|| (v.length < 9)) is okay. but it becomes true even if the use has entered less than 9 characters (and greater than 0). a better way to do this might be:

    if (v.length != 9) neda?

    and also start thinking a bit about regular expressions. they are very very handy when using js. it takes some time to learn but once u master them, u can do many things. even i have forgotten them now but should pick up.

    for example your current code will say it's correct even if the use entered ABCD-ABCD OR 1234-1234 OR 1234-ABCD, neda? Regular expressions may be the best and most effective way to check for the validity of the string according to user specified rules like yours. so Google it up and give it a try

    but u have started well! keep improving to fix the mistakes. that's how u will write a great rego. number checker! :)
     
    Last edited:

    maxXxa

    Member
    Apr 14, 2010
    341
    5
    0
    bro, you have taken a good effort to solve this one. good work. keep improving your answer to get better results.

    if((v== "")|| (v.length < 9)) is okay. but it becomes true even if the use has entered less than 9 characters (and greater than 0). a better way to do this might be:

    if (v.length != 9) neda?

    and also start thinking a bit about regular expressions. they are very very handy when using js. it takes some time to learn but once u master them, u can do many things. even i have forgotten them now but should pick up.

    for example your current code will say it's correct even if the use entered ABCD-ABCD OR 1234-1234 OR 1234-ABCD, neda? Regular expressions may be the best and most effective way to check for the validity of the string according to user specified rules like yours. so Google it up and give it a try

    but u have started well! keep improving to fix the mistakes. that's how u will write a great rego. number checker! :)

    thank u bro...your words are really encouraging... thanxx again .. :)
     

    maxXxa

    Member
    Apr 14, 2010
    341
    5
    0
    Write a HTML document which will ask the user to enter his/ her email address,
    validate it and prints a message

    Enter your e-mail address [email protected]

    validate (button)

    Correct !! >> alert if correctly entered.