Hello,

Ho il seguente codice che, tra le altre cose, dovrebbe convalidare i numeri di telefono degli Stati Uniti con il formato: "(800) 800-8000" con il trattino, parentesi e spazi facoltativi. La regexp è: / ^ \ ((\ d {3}) \?) [-] (\ d {3}) [-] (\ d {4}) $ /??

Il mio problema principale è che è convalida anche numeri come 800 o 800.000 miliardi, ecc
Il codice funziona perfettamente su pagine di prova, ma non sul mio sito.
Qualcosa di simile accade anche per il codice postale.

Qualcuno può dirmi che cosa potrebbe essere sbagliato?
Grazie!

codice:
(function($){
	$.fn.ax_validate = function(f){
		stopAnim();  // just too much otherwise
		//console.log(typeof f + ', id = ' + f.id);
		var n, el, err = [], msg = [], 
			fmats = {
				'email': /^[\w\.\-]+\x40[\w\.\-]+\.\w{2,4}$/,
				'phone': /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/,
				'zip':   /^\d{5}(-\d{4})?$|[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d/
				};

		$('input[type=text],textarea').each(function(i){
			$(this).val( $.trim($(this).val()) );
		});

		$('label.req').each(function(i){
			n = $(this).attr('for');
			el = $('input[name=' + n + ']');

			if (typeof fmats[n] != 'undefined' && !el.val().match(fmats[n])) {
				err.push(n);
				msg.push($(this).text() + ((el.val() == '') ? '' : ' (invalid format)'));
				$(this).animate({color: '#A60'}, 1000);
			
			} else if (el.val() == '') {
				err.push(n);
				msg.push($(this).text());
				$(this).animate({color: '#A00'}, 1000);
			
			} else {
				$(this).css('color', '#0f4068');
			}
		});
		if (err.length == 0) {
			//alert('All ok!');
			//f.submit();
			return true;
		}
		alert('Please fix the following required fields:

' + msg.join('
'));
		//$('input[name=' + err[0] + ']').focus();
		return false;
	};
})(jQuery);