Saturday, February 14, 2015

Javascript, remove extra characters in a string

Trim test Get only numbers:
Get only LowerCase:
Get only Alpha chars:
Code:
function onlyNumbers(x){
 x.value = x.value.replace(/[^0-9]/g,'');
}

function onlyLowercase (x){

x.value = x.value.replace(/[^a-z]/g,'');
}

function onlyAlhpa (x){
x.value = x.value.replace(/[^aA-zZ]/g,'');
}

No comments:

Post a Comment

CSS tricks

Mixed paint in background: background: linear-gradient(to right, #b6e358, #38b143) Grid view: display: grid; grid-template-columns: a...