• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

validating a text box using javascript

I have a javascript that reads the value of the firstname
textbox on a form.

If a number was entered I want it to return an alert and
say that you can only enter a string

var vFirstName = document.getElementById("<%= txtFirstName.ClientID %>")

I tried to use the "typeof" something like the code below but its not working

 var vFirstName = document.getElementById("<%= txtFirstName.ClientID %>")
            var getValueFirstName = vFirstName.value
            var result = (typeof getValueFirstName);
            if (result != 'string') {
                alert("First name should be string or letters");
                return false;

please assist
1 Solution
If isNaN(document.getElementById("<%= txtFirstName.ClientID %>")
will be true if the field is a string, or empty.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now