Ver Mensaje Individual
  #5 (permalink)  
Antiguo 11/11/2008, 12:58
Avatar de stock
stock
 
Fecha de Ingreso: junio-2004
Ubicación: Monterrey NL
Mensajes: 2.390
Antigüedad: 19 años, 10 meses
Puntos: 53
Respuesta: regExp para nombres de usuario

aqui la tienes

var regex = /^[\w-]+$/;

esa expresión retorna true para cuando solo hay valores alphanumericos o guiones, aqui algunos testcases

Código:
var regex = /^[\w-]+$/;

console.debug(regex.test('stock'));
console.debug(regex.test('stock-sk8'));
console.debug(regex.test('stock182'));
console.debug(regex.test('stock_182'));
console.debug(regex.test('stock-7'));
console.debug(regex.test('&/stock_182'));
console.debug(regex.test('st?ock_%182'));
console.debug(regex.test('stock*-7'));
saludos