• 0

form registration


Question

I have a form registration for my site, so the username shouldn't have spaces or special characters.... i want only to allow letters, numbers and underscores(_).. how can i do that???.. i need to validate before including them in the DB but i cant do it ..

Could you guys give me a hand??

Thanks!

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

try this

Javascript

function validForm(Form) {
	invalidCharPW = "@ ~`!#$%^&*()-+=|\[];:>,</?"
 ?if (Form.username1.value == "") { ? ?// Username - is the username box empty?
 ?	alert("You must enter a username")
 ?	Form.username1.focus()
 ?	return false
 ?}
 ?for (i=0; i<invalidCharPW.length; i++) {	// Username - do they contain invalid characters?
 ?	badCharPW = invalidCharPW.charAt(i)
 ?	if (Form.username1.value.indexOf(badCharPW,0) > -1) {
 ? ?alert("Username can only contain letters, numbers, or underscores")
 ? ?Form.username1.focus()
 ? ?Form.username1.select()
 ? ?return false
 ?[b]HTML[/b]

HTML

<FORM onsubmit="return validForm(this)" ACTION="??" METHOD="post">
<input name="username1" size="15" maxlength="15"> (6-15 characters consisting of letters, numbers, or underscore only)
</FORM>

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.