Can anyone think why this wouldn’t work?
It needs to validate a 4 digit postcode
I think im doing something wrong with ||
function numVal()
{
var pc = document.Forders.postcode.value;
if(isBlank(pc) || !isNum(pc) || pc.length != 4)
{
alert(“Please enter a valid Post Code”);
document.Forders.postcode.focus();
}
}
Have you defined isBlank and isNum?
Hi,
Im trying to write a function like this;
function post()
{
var x=document.Forders.postcode.value;
if( x isnt a num || x isnt equal to 4 characters/num in legth)
then
alert(invalid postcode)
}
Except actually in javascript
Im really new to javascript a i am getting there though.
any suggestions/leads?
Well if you added those two functions then the code in your first post would work.
what do you mean set those two functions, im so confused?
any help would be appreciated
He’s referring to this line here:
if([color="blue"]isBlank[/color](pc) || ![color="blue"]isNum[/color](pc) || pc.length != 4)
Those functions do not normally exist, so you need to create those functions.
okay ive set up those functions and it all works 
except for the pc.length != 4 bit which i thought was the most straight forward part!!
any ideas?
Youre right, that is strange. A sample test page wouldn’t hurt, so we can tell exactly what’s going on there.
Is this what you mean by sample page? Its just the js
function numVal() //number validation master
{
var pc = document.Forders.postcode.value;
if(isBlank(pc) || !isNum(pc) || pc.length != 4)
{
alert(“Please enter a valid Post”);
document.Forders.postcode.focus();
}
var hp = document.Forders.homeP.value;
if(isBlank(hp) || !isNum(hp) || hp.length !=10)
{
alert(“Please enter a valid contact number”);
document.Forders.homeP.focus();
}
}
function isNum()// number validation is number
{
if(isNaN(document.Forders.postcode.value))
{
alert(“Only numbers are allowed.”);
Forders.postcode.focus();
return false;
}
if(isNaN(document.Forders.homeP.value))
{
alert(“Only numbers are allowed.”);
Forders.homeP.focus();
return false;
}
}
function isBlank()//number validation isnt blank
{
if (document.Forders.postcode.value.length == 0 )
{
alert(“Please enter your postcode”);
return false;
}
if (document.Forders.homeP.value.length == 0 )
{
alert(“Please enter a valid contact number”);
return false;
}
}
I don’t know where to begin, I’m sorry.
Let’s give it a try.
The isNum() function and the isBlank() function are supposed to receive their values via the function arguments. They should not reach out and control things that are not given to them.
So for example, the isBlank function could be as simple as:
function isBlank(str) {
return str === '';
}
Thanks for replying
don’t worry about those functions i can fix those functions up, any idea on the length not equal to 4 thing?
i got it there was a!in the wrong spot!!