Revision: 35286
Updated Code
at November 5, 2010 02:26 by virgil
Updated Code
checkPhone = '0a635++3Kjhsk9++87$%^&*(100.6'3=-2'; checkPhone.replace(/[^0-9]/g, ''); //returns numbers //result: 06353987100632 checkPhone.replace(/[^\-;\+]/g, ''); //returns + and - //result: ++++- checkPhone.replace(/[0-9]/g, ''); //removes 0-9 //result: a++Kjhsk++$%^&*(.'=- checkPhone.replace(/[0-9\-;\+]/g, '') //removes 0-9 and - and + //result: aKjhsk$%^&*(.'= //------------------------------OR TRY THIS------------------------------------ var error = false; checkPhone = $.trim($('input#phone').val()); stripCheck = checkPhone.replace(/[0-9\-;\+]/g, ''); if(stripCheck.length > 0) //checking for invalid chars (valid: 0-9, +, -) error = true; //console.log('invalid chars found'); numbers = checkPhone.replace(/[^0-9]/g, ''); if(numbers.length < 10) //checking if there is atleast 10 digits error = true; //console.log('more then 10 digits pls'); if(checkPhone.replace(/[^\+]/g, '').length>1 || checkPhone.replace(/[^\-]/g, '').length>1) //there can be only one char of either + or - error = true; //console.log('too many + or -'); if(numbers.substr(0, 2) == '06' && numbers.length != 10) //if 06 it has to have 10 digits error = true; //console.log('06 error'); if(numbers.substr(0, 5) == '00316' && numbers.length != 13) //if 00316 it has to have 13 digits error = true; //console.log('00316 error'); if(checkPhone.substr(0, 4) == '+316' && numbers.length != 11) //if +316 it has to have 11 digits error = true; //console.log('316 error'); console.log(error);
Revision: 35285
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 5, 2010 01:11 by virgil
Initial Code
checkPhone = '0a635++3Kjhsk9++87$%^&*(100.6'3=-2'; checkPhone.replace(/[^0-9]/g, ''); //returns numbers //result: 06353987100632 checkPhone.replace(/[^\-;\+]/g, ''); //returns + and - //result: ++++- checkPhone.replace(/[0-9]/g, ''); //removes 0-9 //result: a++Kjhsk++$%^&*(.'=- checkPhone.replace(/[0-9\-;\+]/g, '') //removes 0-9 and - and + //result: aKjhsk$%^&*(.'=
Initial URL
Initial Description
Initial Title
regex - dutch 06 check
Initial Tags
Initial Language
Regular Expression