Discuz!这个论坛程序一直都是大多数站长喜欢的论坛社区程序,特别是最新推出的Discuz! X2.0正式版更让喜爱的它的用户惊喜不已。然而一个产品的完美程序是有限,就一些小的细节来说,也有些需要改进的地方。比如在论坛想要实现只允许中文用户名注册,却不能在后台进行设置,只能自己进行一番修改。下面我就如何实现Discuz!X2.0限制中文、英文和数字注册的相关问题进行一番探讨。
一、只允许输入使用中文注册的方法
打开:template----default----member----register.htm 如使用的不是默认风格 就找你使用的风格包里
查找:
<div class="rfm">
<table>
<tr>
<th><span class="rq">*</span><label for="{$this->setting['reginput']['username']}">{lang username}:</label></th>
<td><input type="text" id="{$this->setting['reginput']['username']}" name="" class="px" tabindex="1" autocomplete="off" size="25" maxlength="15" required /></td>
<td class="tipcol"><i id="tip_{$this->setting['reginput']['username']}" class="p_tip">{lang register_username_tips}</i><kbd id="chk_{$this->setting['reginput']['username']}" class="p_chk"></kbd></td>
</tr>
</table>
</div>
修改为:
<div class="rfm">
<table width="50%">
<tr>
<th>友情提示:本论坛 『 <font color=red>只接受中文注册</font> 』用户名*</th>
</tr>
</table>
</div>
<div class="rfm">
<table>
<tr>
<th><span class="rq">*</span><label for="{$this->setting['reginput']['username']}">{lang username}:</label></th>
<td><input type="text" id="{$this->setting['reginput']['username']}" name="" class="px" tabindex="1" autocomplete="off" size="25" maxlength="15" onpropertychange="with(this)if(/[^\u3447-\uFA29]/ig.test(value))value=value.replace(/[^\u3447-\uFA29]/ig,'')" required /></td>
<td class="tipcol"><i id="tip_{$this->setting['reginput']['username']}" class="p_tip">{lang register_username_tips}</i><kbd id="chk_{$this->setting['reginput']['username']}" class="p_chk"></kbd></td>
</tr>
</table>
</div>
二、只允许输入英文注册的方法
上面代码中的红色部分,替换为:
onkeyup="this.value=this.value.replace(/[^\a-\z|A-Z]/g,'')" onblur="this.value=this.value.replace(/[^\a-\z|A-Z]/g,'')"
三、只允许输入数字注册的方法
上面代码中的红色部分,替换为:
onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
大家可以试试看,大家也可以一块探讨以下问题:
1、如何限制用户注册第一个字符不能是数字?
2、如何限制用户注册用户名不能是纯数字?
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
