/    Sign up×
Community /Pin to ProfileBookmark

Form Validation

I have some form validation done, but it’s not very good. How do i make sure that users can only use a-z, A-Z, 0-9. (there for users would not be able to use special characters) – note: i have the php server side validation done but i want javascript also, thanks

Here is the code i have so far:

[code=html]function validate_username(field,alerttxt)
{
with (field)
{
numofchar=value.length;
if (numofchar<5)
{alert(alerttxt);return false}
else {return true}
}
}[/code]

[code=html]function validate_form(thisform)
{
with (thisform)
{

if (validate_username(username,”Ooops… Username must be at least 5 characters in length”)==false)
{username.focus();return false}[/code]

how can i make sure that the $username only can have a-z, A-Z, 0-9

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@samanyoluJun 19.2007 —  <br/>
&lt;script type="text/javascript"&gt;

function check(){

var el = document.getElementById('inputid');
var re = /^[a-zA-Z0-9]{5,}$/
if(re.test(el.value)) { alert("okey");return true; }
if(!re.test(el.value)) { alert(" not okey"); el.focus() ; return false; }
}

&lt;/script&gt;
&lt;input type="text" id="inputid" onchange="check()"&gt;
×

Success!

Help @oo7ml spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...