JAVASCRIPT HELP..!!!

maxXxa

Member
Apr 14, 2010
341
5
0
bro.. hi im new here...btw starting with a question ...
want to knw how 2 write a javascript code to validate NIC number.... and prints a message saying OK...

i jz tried
<script type ="text/JavaScript>
function validate(){
var v = document.getElementById("nic").value;
if(v.length<11){
if(v.charAt(10)=='v')

plzz help me 2 code this... tell me if its ok up to the point..thnxx
 
  • Like
Reactions: koondeGoda

truth4L

Member
Jan 16, 2009
2,463
10
0
emotional hell
Code:
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="Javascript" type="text/javascript">
            function validate(){
                var nic_no = document.getElementById('nic').value;
                if(nic_no.length == 10 && nic_no.charAt(9)=='V'){
                    alert("NIC number is Valid");
                }else{
                    alert("NIC number is Invalid");
                }
            }
        </script>
    </head>
    <body>
        NIC : <input type="text" id="nic">
        <input value="Check" id="check" type="button" onclick="validate()">

    </body>
</html>

hope this helps.. :)
sorry for being late...
 

maxXxa

Member
Apr 14, 2010
341
5
0
Code:
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="Javascript" type="text/javascript">
            function validate(){
                var nic_no = document.getElementById('nic').value;
                if(nic_no.length == 10 && nic_no.charAt(9)=='V'){
                    alert("NIC number is Valid");
                }else{
                    alert("NIC number is Invalid");
                }
            }
        </script>
    </head>
    <body>
        NIC : <input type="text" id="nic">
        <input value="Check" id="check" type="button" onclick="validate()">

    </body>
</html>

hope this helps.. :)
sorry for being late...
thnxx dude :) aulak na hehe
 

maxXxa

Member
Apr 14, 2010
341
5
0
Code:
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="Javascript" type="text/javascript">
            function validate(){
                var nic_no = document.getElementById('nic').value;
                if(nic_no.length == 10 && nic_no.charAt(9)=='V'){
                    alert("NIC number is Valid");
                }else{
                    alert("NIC number is Invalid");
                }
            }
        </script>
    </head>
    <body>
        NIC : <input type="text" id="nic">
        <input value="Check" id="check" type="button" onclick="validate()">

    </body>
</html>

hope this helps.. :)
sorry for being late...

bro meke ID eke numbers da kiyala check karaganne kohomada
 

koondeGoda

Member
Nov 28, 2007
4,892
35
0
₪ Hyper_Cube ₪
To validate numbers , make a call for this function in your if condition. pass the user input (s) . hope this helps

PHP:
<script type="text/javascript">

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

</script>


OK! here i extended truth4L's code :P

PHP:
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="Javascript" type="text/javascript">

            function validate(){
                var nic_no = document.getElementById('nic').value;
                
                if(nic_no.length == 10 && nic_no.charAt(9)=='V' && isInteger(nic_no.substring(0,9) )){
                    alert("NIC number is Valid");
                }else{
                    alert("NIC number is Invalid");
                }
                
            }
            
            function isInteger(s) 
            {   var i; 
                for (i = 0; i < s.length; i++) 
                {    
                // Check that current character is number. 
                    var c = s.charAt(i); 
                    if (((c < "0") || (c > "9"))) return false; 
                } 
                // All characters are numbers. 
                return true; 
            }

        </script>
    </head>

    <body>
        NIC : <input type="text" id="nic">
        <input value="Check" id="check" type="button" onclick="validate()">

    </body>
</html>
 
Last edited:

truth4L

Member
Jan 16, 2009
2,463
10
0
emotional hell
ayya dan meke apita ID eka abcd kiyala ganhannath puluwnne... ehema nathuwa numbers witharak gahanna hadanne kohomda ...ea kiwwe characters gahuwoth invalid kiyala enna

Code:
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="Javascript" type="text/javascript">
           
            var digitCheck;
            function validate(){



                var nic_no = document.getElementById('nic').value;
                var nic_digits = nic_no.split(8);
                
                var a = nic_digits[0]+nic_no.charAt(8);

                checkNumbers(a);

                if(nic_no.length == 10 && nic_no.charAt(9)=='V'){
                    if(digitCheck){

                        alert("NIC number is Valid");
                    }else{

                        alert("NIC number is Invalid");
                    }
                   
                }else{
                    alert("NIC number is Invalid");
                }
            }

            function checkNumbers(numbers){
                var numericExpression= /^[0-9]+$/;
                if(numbers.match(numericExpression)){
                    digitCheck = true;
                }else{
                    digitCheck = false;
                }

            }

        </script>
    </head>
    <body>
        NIC : <input type="text" id="nic">
        <input value="Check" id="check" type="button" onclick="validate()">

    </body>
</html>

poddak modify kala.. :)
 

maxXxa

Member
Apr 14, 2010
341
5
0
To validate numbers , make a call for this function in your if condition. pass the user input (s) . hope this helps

PHP:
<script type="text/javascript">

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

</script>


OK! here i extended truth4L's code :P

PHP:
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="Javascript" type="text/javascript">

            function validate(){
                var nic_no = document.getElementById('nic').value;
                
                if(nic_no.length == 10 && nic_no.charAt(9)=='V' && isInteger(nic_no.substring(0,9) )){
                    alert("NIC number is Valid");
                }else{
                    alert("NIC number is Invalid");
                }
                
            }
            
            function isInteger(s) 
            {   var i; 
                for (i = 0; i < s.length; i++) 
                {    
                // Check that current character is number. 
                    var c = s.charAt(i); 
                    if (((c < "0") || (c > "9"))) return false; 
                } 
                // All characters are numbers. 
                return true; 
            }

        </script>
    </head>

    <body>
        NIC : <input type="text" id="nic">
        <input value="Check" id="check" type="button" onclick="validate()">

    </body>
</html>

thnxx bro.. great help
 

truth4L

Member
Jan 16, 2009
2,463
10
0
emotional hell
To validate numbers , make a call for this function in your if condition. pass the user input (s) . hope this helps

PHP:
<script type="text/javascript">

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

</script>
OK! here i extended truth4L's code :P

PHP:
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="Javascript" type="text/javascript">

            function validate(){
                var nic_no = document.getElementById('nic').value;
                
                if(nic_no.length == 10 && nic_no.charAt(9)=='V' && isInteger(nic_no.substring(0,9) )){
                    alert("NIC number is Valid");
                }else{
                    alert("NIC number is Invalid");
                }
                
            }
            
            function isInteger(s) 
            {   var i; 
                for (i = 0; i < s.length; i++) 
                {    
                // Check that current character is number. 
                    var c = s.charAt(i); 
                    if (((c < "0") || (c > "9"))) return false; 
                } 
                // All characters are numbers. 
                return true; 
            }

        </script>
    </head>

    <body>
        NIC : <input type="text" id="nic">
        <input value="Check" id="check" type="button" onclick="validate()">

    </body>
</html>


lolz me deela tiyenne.. :P
 

maxXxa

Member
Apr 14, 2010
341
5
0
Code:
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="Javascript" type="text/javascript">
           
            var digitCheck;
            function validate(){



                var nic_no = document.getElementById('nic').value;
                var nic_digits = nic_no.split(8);
                
                var a = nic_digits[0]+nic_no.charAt(8);

                checkNumbers(a);

                if(nic_no.length == 10 && nic_no.charAt(9)=='V'){
                    if(digitCheck){

                        alert("NIC number is Valid");
                    }else{

                        alert("NIC number is Invalid");
                    }
                   
                }else{
                    alert("NIC number is Invalid");
                }
            }

            function checkNumbers(numbers){
                var numericExpression= /^[0-9]+$/;
                if(numbers.match(numericExpression)){
                    digitCheck = true;
                }else{
                    digitCheck = false;
                }

            }

        </script>
    </head>
    <body>
        NIC : <input type="text" id="nic">
        <input value="Check" id="check" type="button" onclick="validate()">

    </body>
</html>

poddak modify kala.. :)
thnk u bro.. :)
 

maxXxa

Member
Apr 14, 2010
341
5
0
write a HTML page which allows entering the appointment date of an employee & calculate the bonus.

permanent employee - 01 month salary as bonus if worked more than 2 years.
if the period is between 1 & 2 50% from the basic salary.
if less than 01 year 20% from basic.
For a TEMPORARY employee bonus will be 5% from BASIC.

pahala widihata thama bro design karanna kiyala thiyenne... anee podi hari help ekak denna bro loku pinak... thnxx

Name :____text field
Date of Appointment :____text field
Basi Salary :_______ text field

temporary [radio button] permanent[radio button]

calculate [button]

meke mulinma date eka years check karaganna oone.. eeta passe basic eka [STRING] eka INTEGER walata convert karala eken amount eka ganna oone... eeta passe mona radio button ekada click karala thiyenne kiyala balala ekata answer eka denna ooone.,.. ehema harida mchn.. ookata step by step yanna ooneda ... mata code eka gahanna thama danne naththe.... kauruhari plzz comments ekka code karala help ekak denawada..??
 
Last edited: