i hate asking for help as i would rather figure things for myself, or learn from what others have posted or already asked and solved. as such this is my first post on here!
This is either really really simple and im over complicating things or im going about it the wrong way. ive been searching everywhere for over 2 hours now. im not exactly a noob at js but i am still sort of new,i would say learning, ameteur?? anywho....
what i am trying to do:
so i have a number input box <input type="number" maxlength="4" .../>
where a user will enter a 4 digit number (needs to be 4 digits) from 100 to 8000. so obviously 100 to 999 would be 0100 - 0999.
no problem so far, i can just use a string to pass the variable through as 4 digits.
the problem i have is that i need to add certain conditions to validate the input. one condition is bugging me. this is what i have so far:
(var x is already set to the form and number input box)
if (x=="" || isNaN(x) || x.length!== 4 && x< 0100 || x>8000)
{alert(please enter the correct amount!}
else {run rest of function}
so they all work execpt for:x<0100
if the user enters 99 it flags up because it is not 4 digits and if they enter 0099 it accepts it and runs the rest of the function code.
i just need it to alert for any amount from 0001 to 0099.
i found another post, How to make 8 digit number in javascript? , sort of relevant but the guy just wants to output a number padded with zeros. i think one of the solutions (code below) may be of use to me but as i am rather tired, brain frazzled and new i cant solve it:
var i = (100).toPrecision(8).split('.').reverse().join('');
i would start by editing it to:
var i = (x).toPrecision(4).split('.').reverse().join('');
(but would this only work if they typed 99 not 0099...if ya see what i mean)
i think it would be like a reverse of the code (split 0099 to 99.00) , and then the statement would be: if(.... && i<==99 || ....)
but idk how to write it in JS...
ok so do ya see how this is messing with me mind, being a semi/quarterly noob and all!!
sorry its not formatted correctly and so long, i havent grasped how to use the code functions...
and thanks for your patience in reading this (if you got this far hehe).
THANKS IN ADVANCE
Slappy-x