Forums

This topic is locked

Spaces

Posted 03 Jul 2003 01:57:46
1
has voted
03 Jul 2003 01:57:46 Ken Dobson posted:
Does anyone know how to prevent spaces from being put into a text box? I'm trying to prevent people from creating a username with a space. I'm not talking about trimming up the username and removing the spaces before it's submitted however. I'm looking to verify if there are spaces in the username before submitting, and if there are, then pop up an alert window. Once there are no spaces, then they should be able to save their profile.

Thanks,

Ken

Replies

Replied 04 Jul 2003 03:06:37
04 Jul 2003 03:06:37 David Behan replied:
I use this little ASP script I worte to check if a password is ok. You can modify it to check the username.

<%
IF Request.Form("change" = "y" THEN

oldpassword = lcase(Request.Form("old_1")
newpassword1 = lcase(Request.Form("new_1")
newpassword2 = lcase(Request.Form("new_2")

'Check that the old password was entered correctly... for security reasons.
IF oldpassword <> cust_password THEN
errorno = errorno + 1
errortext = errortext & "<b>" & errorno & ".</b> Old password is incorrect.<br>"
END IF

'Check new password has been verified
IF newpassword1 <> newpassword2 THEN
errorno = errorno + 1
errortext = errortext & "<b>" & errorno & ".</b> New passwords entered do not match.<br>"
END IF

'Check the length of the password is between 6 and 12 characters
IF Len(newpassword1) < 6 OR Len(newpassword1) > 12 THEN
errorno = errorno + 1
errortext = errortext & "<b>" & errorno & ".</b> New password must be between 6 and 12 characters in length.<br>"
END IF

'Check the password has only certain type of characters in use
IF inStr(newpassword1,"'" > 0 OR inStr(newpassword1,"#" > 0 OR inStr(newpassword1,"!" > 0 OR inStr(newpassword1,"£" > 0 OR inStr(newpassword1,"$" > 0 OR inStr(newpassword1,"%" > 0 OR inStr(newpassword1,"^" > 0 OR inStr(newpassword1,"&" > 0 OR inStr(newpassword1,"*" > 0 OR inStr(newpassword1,"(" > 0 OR inStr(newpassword1,"" > 0 OR inStr(newpassword1,"-" > 0 OR inStr(newpassword1,"+" > 0 OR inStr(newpassword1,"=" > 0 OR inStr(newpassword1,"[" > 0 OR inStr(newpassword1,"{" > 0 OR inStr(newpassword1,"]" > 0 OR inStr(newpassword1,"}" > 0 OR inStr(newpassword1,"~" > 0 OR inStr(newpassword1,"@" > 0 OR inStr(newpassword1,";" > 0 OR inStr(newpassword1,":" > 0 OR inStr(newpassword1,"|" > 0 OR inStr(newpassword1,"\" > 0 OR inStr(newpassword1,"/" > 0 OR inStr(newpassword1,"?" > 0 OR inStr(newpassword1,">" > 0 OR inStr(newpassword1,"<" > 0 OR inStr(newpassword1,"." > 0 OR inStr(newpassword1,"," > 0 OR inStr(newpassword1,"_" > 0 THEN
errorno = errorno + 1
errortext = errortext + "<b>" & errorno & ".</b> New password must only contain letters (a-z) and numbers (0-9).<br>"
END IF


<font color=red>'Check that there are no spaces in the new password entered
IF InStr(newpassword1," " &gt; 0 THEN
errorno = errorno + 1
errortext = errortext & "&lt;b&gt;" & errorno & ".&lt;/b&gt; New password must not contain any spaces.&lt;br&gt;"
END IF</font id=red>

IF NOT errorno &gt; 0 THEN
'The new and old passwords are ok so we change the password.
statustext = statustext & "Your password has been changed successfully.&lt;br&gt;"

newpassword1 = lcase(newpassword1)
newpassword1 = Replace(newpassword1,"'",""

sql_table = "TBL_CUSTOMERS"
sql_set = "CUST_PASSWORD = '" & newpassword1 & "'"
sql_where = "CUST_ID = " & cust_id

CALL UpdateRecord(updPassword,sql_table,sql_set,sql_where)

Response.Cookies("dynamic_password" = newpassword1

END IF

END IF
%&gt;

The bit in red is what you are looking for.

Regards,

Dave

_________________________
WinXP : IIS 5.1 : StudioMX : ASP : VBScript
www.dynamic.ie

Edited by - beano on 04 Jul 2003 03:07:21

Reply to this topic