﻿/* 
    Document   : validation.js
    Created on : 21-Jan-2010
    By         : Joel Phillips - POS Direct Ltd
*/

//function isNum(i){
//    var chrChar = (i.which) ? i.which : i.keyCode
//    if(chrChar > 31 &&( chrChar < 48 || chrChar > 57)){
//        return false
//     }
//    return true
//} //isNum

function formatPhone(i) {
    //accepts text box - gets value and formats it to 4-3-{4} for telephone reg expression validation
    var str = i.value
    str = str.split(' ').join('');
    i.value = str.substr(0, 4) + " " + str.substr(4, 3) + " " + str.substr(7, str.length)
} //formatPhone

function formatPostcode(i) {
    //accepts text box - gets value and formats it to UCASE (3|4)-3 postcode for reg expression validation
    var str = i.value
    str = str.split(' ').join('');
    if (str.length == 5) {
        i.value = (str.substr(0, 2) + " " + str.substr(2, 3)).toUpperCase()
    }
    else if(str.length == 6) {
        i.value =  (str.substr(0, 3) + " " + str.substr(3, 3)).toUpperCase()
    }
    else if (str.length == 7) {
        i.value = (str.substr(0, 4) + " " + str.substr(4, 3)).toUpperCase()
    }
    
} //formatPostcode


