how can I disallow special characters, space, capital letter, dot in user name on registration?

please try below function for disallow special characters, space, capital letter, dot in user name on registration

 //add a filter to invalidate a username with spaces,special characters, capital letter, dot
    add_filter('validate_username','restrict_space_in_username',10,2);
    function restrict_space_in_username($valid,$user_name){
     //check if there is an space
     if ( preg_match('/\s[!@#$%^&*()+=\-\[\]\';,.\/{}|":<>?~\\\\][A-Z](.)/',$user_name) )
     return false;//if myes, then we say it is an error
     return $valid;//otherwise return the actual validity
    }