Javascript使用输入创建用户名 [英] Javascript creating a username using inputs

查看:104
本文介绍了Javascript使用输入创建用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户输入各种信息的表单。输入选择的名称允许用户输入选择的用户名,但需要集成HIDDEN INPUT以便创建系统用户名。

I have a form in which the user inputs various information. The input chosen name allows the user to enter a username of choice but a HIDDEN INPUT needs to be integrated so that a system username is created.

系统用户名是在javascript函数提交的页面上生成的,它包含在姓氏,街道地址,给定名称中找到的第一个字母字符;这个月的数字日;和提交时间的数字秒字段。例如:用户在2014年4月25日12:31:16注册名称Bernardo O'Higgins,地址为213 Liberator St。他的系统用户名为
OLB2516。这样我就可以看到它是否有效,目前ssytem用户名没有隐藏,只是一个普通的文本框。

The system username is generated on page submit by a javascript function, and it consists of the first alphabetic characters found in the Family name, street address, Given name; the numerical day of the month; and the numerical seconds field of the time of submission. E.g.: A user registers with name Bernardo O’Higgins, address 213 Liberator St, at 12:31:16 on 25 April 2014. His system username is OLB2516. Just so i can see if it works, at the moment the ssytem username is not hidden but just a normal text box.

我完全迷失了,因为我不知道如何去做这个,希望有人可以帮助我?这是我的PHP文件与表单集成。

I am totally lost as i do not know how to go about this and hoping somebody can help me? Here is my php file with form integrated.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />

<title>Registration</title>


</head>

<body>
<?php
$conn = mysql_connect("localhost", "....", ".....");
mysql_select_db("tipping291", $conn)
or die ('Database not found ' . mysql_error() );




mysql_close($conn); 
?>

<div id="container">
<div id="header">

<h1>Registration</h1></div>

<div id="menu">
<a href="home.php"><h2>Homepage</h2></a><br />
<a href="rego.php"><h2>Registration</h2></a><br />
<a href="userlogin.php"><h2>User Login</h2></a><br />
<a href="adminlogin.php"><h2>Administrator Login</h2></a><br />
<a href="tipping.php"><h2>Tipping</h2></a><br />
<a href="termsnconditions.php"><h2>Terms & Conditions</h2></a><br />
</div>

<form id="rego" action="<?php echo 
htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" onSubmit="return       validateForm()">

<label>Given Name:</label> <input type="text" name="gname"><br />
<br />
<label>Middle Name: </label><input type="text" name="mname"><br />
<br />
<label>Family Name:</label> <input type="text" name="surname"><br />
<br />
<label>Chosen Username:</label> <input type="text" name="username"><br />
<br />
<label>Address:</label> <input type="text" name="address"><br />
<br />
<label>Postcode: </label><input type="text" name="postcode"><br />
<br />
<label>State:</label> <input type="text" name="state"><br />
<br />
<label>Tel number: </label><input type="text" name="tel"><br />
<br />
<label>Password:</label> <input type="password" name="password"><br />
<br />
<label>Password confirmation:</label> <input type="password" name="passconfirm"><br />
<br />
<label>System username</label> <input type="text" name="susername" >
<input type="submit" value="submit">
</div>
</form>
</body>

</html>

CAN SOMBODY PEASE HELP ME !!!!!我有任何成功

CAN SOMBODY PEASE HELP ME!!!!! I HAVENT HAD ANY SUCCESSS

推荐答案

在关闭之前添加以下代码} of function validateForm(){并尝试

Add the below code before closing } of function validateForm() { and try

var username = '';
var date = new Date();
$.each(['surname', 'address', 'gname'], function() {
    username += $.trim($('input[name="' + this + '"]').val().replace(/\d+/g, '')).substring(0, 1);
});
username += date.getDate() + '' + date.getSeconds();
$('input[name="susername"]').val(username);

jsBin

这篇关于Javascript使用输入创建用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆