Solved

validating a text box using javascript

Posted on 2013-01-04
1
296 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
1 Comment
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now