Jump to content
Sign in to follow this  
knutsford

<input required>

Recommended Posts

For that you'll need Javascript.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>title</title>
<script>
window.onerror = function(a,b,c){
alert('Javascript Error: '+a+'\nFile: '+b+'\nLine: '+c);
return true;
}
</script>
<script>
'use strict';

function validateForm(evt){
var txt = document.getElementById('txt1').value.trim();
if (txt.length < 8){
evt.preventDefault();
alert('Submission Aborted\nText is only ' + txt.length + ' characters');
}
}

window.onload = function(){
document.getElementById('form1').onsubmit = validateForm;
}

</script>
</head>

<body>

<form id="form1">
<input type="text" name="txt1" id="txt1"/>
<input type="submit" value="Submit"/>
</form>

</body>    
</html>

Share this post


Link to post
Share on other sites

You can use the pattern attribute:

<input required pattern="\s*\S{8,}\s*">

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...