Alex Rivera | Logout

A regex to match strings with alphanumeric, spaces and punctuation

Asked 2011-08-29T17:17:21.573
21

I need a regular expression to match strings that have letters, numbers, spaces and some simple punctuation (.,!"'/$). I have ^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$ and it works well for alphanumeric and spaces but not punctuation. Help is much appreciated.

Edit
Report

1 Answer

1
<script type="text/javascript">
check("hello dfdf asdjfnbusaobfdoad fsdihfishadio fhsdhf iohdhf");
function check(data){
var patren=/^[A-Za-z0-9\s]+$/;
    if(!(patren.test(data))) {
       alert('Input is not alphanumeric');       
       return false;
    }
    alert(data + " is good");
}
</script>
answered 2013-04-25T09:10:17.150

Your Answer