jQuery Each()

I have a form with 4 text input fields that I need to make sure are numeric. Each input field has a class of .laser_numeric and the form ID is #laser_finder.

Each time there is a change on th form I want to check to make sure it is either numeric or empty.  If any are not numeric (Alpha) I open an Overlay with a message box.  The message box can be closed.

The following code only works on the first field with the class .laser_numeric.  I need it to work on all four.

$(function () {
 $("#laser_finder").change(function(e) {
	 var director = $("input.laser_numeric").val();
	 if(director=="" || ($.isNumeric($('input.laser_numeric').val()))){
		 return true;
	 	} else {
	 	      	$('#close-dialog').click(function() {
	 		return false;

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
You could just prevent the user from typing anything but numbers and be done with it. Have a look at this jsfiddle example. If you need a period for decimal numbers you can modify the script to include a period.

But if you insist on using your script, the solution is to use the class name of the inputs rather than the id of the form as in this jsfiddle example.
rgranlundAuthor Commented:
How do I add a decimal point to:
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;

    return true;

Open in new window

Tom BeckCommented:
You can just change charCode > 48 to charCode > 46 as a quick fix to allow a period. Really though, it needs to be more elaborate. You should prevent more than one period from being entered into each input and consider if values can start with zero or not. There are plenty of examples all over the internet for this kind of script. You could also use regex expressions (which I'm not well versed on).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.