Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Form Validation quicky

Featured Replies

I want user to enter there name in text field, but it cant contain numbers only letters. how can i do this??? here is my code

 

function validator() {

	var jerseynumber = document.getElementById("jersey_number").value;
	var firstname = document.getElementById("firstname").value;

	if (isNaN(jerseynumber)||jerseynumber<1||jerseynumber>100) {
		alert("Not a valid number");
	}
	if (firstname!=[A-Z,a-z]) {
		alert("Not a valid number");
	}

}

Edited by Renaissance-Design
Please use the code button or tags to format your code.

Hi,

 

Make sure you are checking every letter in the firstname. I don't know how you want your program to react when it finds a number but one way is to use a loop to go through each character in the string and check to see that it is not a number. There are other faster ways like using regular expressions but that one is easy to process in the head. My head. :blink:

Edited by rrr

If you're just checking for the presence of a number:

if (/\d/.test(firstname)) {
alert("Ooh, you put a number in your firtname. How do you pronounce that you mofo?!");
}

It's out! The regex is OUT!!!! HE BROUGHT THE REGEX OUT!

Edited by rrr

It's ok. I'll just pretend it's a typo so it doesn't make me wonder why a bunch of characters do the same work as ten lines.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.