<?php

$line = "dsfsdf";
if (!preg_match('/^[a-zA-Z0-9_-]{1,30}$/', $line))
{
   echo 'No Match found';
}
else
{
   echo 'Match found';
}