ajax 用户名验证,php页面怎么写
html代码
<form id="iform" name="iform" method="post" action="__URL__/add">
<label><span>用户名:</span></label>
<input id="username" name="username1" class=":ajax;/mrthink.php" type="text" title="4-20位,注册成功后不可修改"/>
</form>
js代码
/*
*本插件原作者Vanadium,原文请移步前往http://vanadiumjs.com/查看
*转载及使用请务必注明原作者.
*/
/*$(function(){
//必填项加红*,Mr.Think添加,原插件无
// $("input[class*=:required]").after("<span> *</span>")
});*/
//弹出信息样式设置
Vanadium.config = {
valid_class: 'rightformcss',//验证正确时表单样式
invalid_class: 'failformcss',//验证失败时该表单样式
message_value_class: 'msgvaluecss',//这个样式是弹出信息中调用值的样式
advice_class: 'failmsg',//验证失败时文字信息的样式
prefix: ':',
separator: ';',
reset_defer_timeout: 100
}
//验证类型及弹出信息设置
Vanadium.Type = function(className, validationFunction, error_message, message, init) {
this.initialize(className, validationFunction, error_message, message, init);
};
Vanadium.Type.prototype = {
initialize: function(className, validationFunction, error_message, message, init) {
this.className = className;
this.message = message;
this.error_message = error_message;
this.validationFunction = validationFunction;
this.init = init;
},
test: function(value) {
return this.validationFunction.call(this, value);
},
validMessage: function() {
return this.message;
},
invalidMessage: function() {
return this.error_message;
},
toString: function() {
return "className:" + this.className + " message:" + this.message + " error_message:" + this.error_message
},
init: function(parameter) {
if (this.init) {
this.init(parameter);
}
}
};
Vanadium.setupValidatorTypes = function() {
Vanadium.addValidatorType('empty', function(v) {
return ((v == null) || (v.length == 0));
});
//***************************************以下为验证方法,使用时可仅保留用到的判断
Vanadium.addValidatorTypes([
//邮箱是否为空
['ajax1', function(v) {
return !Vanadium.validators_types['empty'].test(v);
}, '用户名必填!'],
['required', function(v) {
return !Vanadium.validators_types['empty'].test(v);
}, '您还没有输入个人或公司电子邮箱!'],
//电话是否为空
['dh1', function(v) {
return !Vanadium.validators_types['empty'].test(v);
}, '您还没有输入个人或公司电话号码!'],
['kong', function(v) {
return !Vanadium.validators_types['empty'].test(v);
}, '注册人/公司名称不能留空!'],
//强制选中
['accept', function(v, _p, e) {
return e.element.checked;
}, '必须