Solved

validating a text box using javascript

Posted on 2013-01-04
1
295 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
Comment Utility
If isNaN(document.getElementById("<%= txtFirstName.ClientID %>")
will be true if the field is a string, or empty.

Cd&
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…

771 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

12 Experts available now in Live!

Get 1:1 Help Now