Click here to Skip to main content
15,888,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys

Can you please help how to make javascript validation?I want to alert a message when a user input both a numeric and a non numeric value in a textfield. e.g. min234.

If the above example was inserted into a textfield a pop up message should be displayed such as "Please enter a non-numeric value only". I've already try that code but it does not work:
C#
function validateFN() 

{ 
var x=document.forms["form1"]["firstname"].value;

if ( isNaN (x) ) 

{ 
alert("Numbers cannot be inserted!"); 

return false; 
} 
} 

Thanks guy please help
Posted
Updated 22-Nov-13 21:01pm
v2

1 solution

You could add one more else if statement to your code like below:

x=document.myForm.myInput.value;

JavaScript
else if(isNaN(x))

    {
        alert("Number cant be alphabet")
        return false
    }

Below is the Full Script

JavaScript
<script>
            function validate(){
    x=document.myForm.myInput.value;

    if (x >=10)

    {
        alert("Number is bigger than 10")
        return true

    }

    else if(isNaN(x))

    {
        alert("Number cant be alphabet")
        return false
    }
    else

    {
        alert("Number is smaller than 10")
        return false
    }

}
    </script>


Further in details if you required you can visit This[^] and This[^] links.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900