Quantcast
Viewing all articles
Browse latest Browse all 130

Extract the first alpha values of a string

This was a requirement of a client of ours, they wanted the first alpha characters of the account postcode to be attached to another field.  However for some reason the IsNaN() & parseInt() methods didnt seem to be working correctly on the form.

I thought id share the function i used as a replacement.

function getNo(pCode)
{
var code = "";
for (n=0;n<=pCode.length;n++){
var i = pCode.substring(n,n+1);
if(i=="1"||i=="2"||i=="3"||i=="4"||i=="5"||i=="6"||i=="7"||i=="8"||i=="9"||i=="0")
{
return code;
}
else
{
code = code + i;
}
}}

alert(getNo(postcode));

Jonathan


Viewing all articles
Browse latest Browse all 130

Trending Articles