开发者

Users to register only lower case letters

I have this register page , and i would like to have the script register only lower case letters : pretty I do not want it to register :Pretty , PRETTy , PRETTY ... Here is the code , what do i need to add , or do i change something in the DB ?

Thanks so much for the help !

public function addField($field_name){

    if (!array_key_exists($field_name, $this->fields))
    {
        if ($field_name=='username') {
            $field = new field_join_username();
            parent::registerField($field);
        }

        if ($field_name=='email') {
            $field = new field_join_email();
            parent::registerField($field);
      开发者_如何学C  }
    }

    parent::addField($field_name);
}


You can use strtolower on the input to convert it to lowercase.


It's not clear to me what this code is part of, but it should be a simple matter of calling strtolower() on the user's input.


u can use regular expression for username in both javascript and php pattern would be

javascript

<script type="text/javascript">
var regex = /^[a-z]$/;
var userinput = jQuery('#username').val();
 if (regex.test(userinput )) {
  alert("VALID username");
 } else {
  alert("INVALID username");
 }
}
</script>

php

$pattern = '/^[a-z]$/';
preg_match($pattern, $userinput, $matches);
print_r($matches);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜