?
Solved

validating a text box using javascript

Posted on 2013-01-04
1
Medium Priority
?
304 Views
Last Modified: 2013-01-04
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
0
Comment
Question by:Sirdots
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 2000 total points
ID: 38744218
If isNaN(document.getElementById("<%= txtFirstName.ClientID %>")
will be true if the field is a string, or empty.

Cd&
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question