The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Pattern not working, Pattern is not limiting the number of elements
spalisetty
post Aug 2 2020, 10:24 AM
Post #1


Novice
**

Group: Members
Posts: 22
Joined: 2-August 20
Member No.: 27,469



Hello,
I have written the code to make sure that the number of characters is between 5 to 10. But it is going beyond and when I click on Register, it is going to different page as well. Kindly let me know where I am going wrong.

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Registration form</title>
</head>
<body>
<form class="" action="ThankYou.html" method="Get">
<h1>Registration form</h1>
<h2>All Fields are Mandatory</h2>
<label for="uname">Name</label>
<input id = "uname" type="text" name="username" placeholder="Enter Name" pattern=".{5, 10}" title="Please
enter a name between length 5 and 10" required><br>
<label for="uemail">Email</label>
<input id = "uemail" type="email" name="email" placeholder="Enter Email" required><br>
<label for="uage">Age</label>
<input id = "uage" type="text" name="age" placeholder="Enter Age" required><br>

<h2>Are you interested in Dating?</h2>
<label for="yessir">Yes</label>
<input id = "yessir" type="radio" name="dating" value="Yes">
<label for="nosir">No</label>
<input id = "notesir" type="radio" name="dating" value="No">

<h2>Your expectation like</h2>
<select class="" name="expectation">
<option value="actress1">sumalatha</option>
<option value="actress2">suhasini</option>
<option value="actress3">jayasudha</option>
<option value="actress4">jayaprada</option>
</select>

<h2>How many Marriages you want?</h2>
<select class="" name="numberofmarriages">
<option value="numberofmarr1">1</option>
<option value="numberofmarr2">2</option>
<option value="numberofmarr3">3</option>
<option value="numberofmarr4">4</option>
</select>

<h2>Are You Heavy Alcoholic</h2>
<label for="yesalcohol">Yes</label>
<input id = "yesalcohol" type="checkbox" name="alcohol" value="Yesal">
<label for="noalcohol">No</label>
<input id = "noalcohol" type="checkbox" name="alcohol" value="Noal">
<label for="somealcohol">Some Times</label>
<input id = "somealcohol" type="checkbox" name="alcohol" value="soal">

<h2>Your Preferences and Extra Information</h2>
<<textarea name="box" rows="8" cols="80"></textarea>

<input type="submit" name="submit" value="Register">
</form>
</body>
</html>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Christian J
post Aug 8 2020, 10:12 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,661
Joined: 10-August 06
Member No.: 7



Out of how many lessons? :-p

Here's a challenge for you: make a tool in e.g. javascript that explaines in clear text what a user-submitted regex actually does (similar to that site, "CSS-explain" was it?).

A tool that creates a regex from various predefined cleartext alternatives might be very useful too, but I suspect the UI will be daunting.
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 8 2020, 10:04 PM
Post #3


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,733
Joined: 9-August 06
Member No.: 6



10. But I expect the remaining chapters to take longer...

In lesson 4 I learnt this
CODE
\w matches any alphanumeric character in upper or lower case and underscore
\W what isn't matched by the above


Sort of handy, except I don't understand why underscore is lumped together with alphanumeric characters, but I'm sure there is a reason, probably to do with some programming language or *nix . Then I tried it in Notetab. Turnes out there it's the other way around! \W matches alphanumeric and underscore. laugh.gif

Now I use an older version of NTB because I had an accident with the upgraded version and haven't bothered to fix it. It changed regex enginge at some point and now uses PCRE. Don't know what it used before, something obscure probably since it isn't mentioned in Help. I'm sure this will work as expected once I get around to install the new version (that I have now got around to obtain from the company).

Strange is that in NTB Help the description of \w and \W is something that I don't even understand but at first glance looks like something different.

CODE
\w   any word delimiter. Matches any of \t\s!"&()*+,-./:;<=>?@[\]^`{|}~
\W   any nonword delimiter. Equivalent to [^\t\s!"&()*+,-./:;<=>?@[\]^`{|}~]


Maybe that means alhpanumeric and underscore and the opposite, I don't know. I get the meaning of "word delimiter", but I don't see how underscore fits in with "nonword delimiter", which should mean alphanumeric characters, and it is matches together with alphanumeric characters in NTB too. wacko.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Aug 9 2020, 07:14 AM
Post #4


.
********

Group: WDG Moderators
Posts: 9,661
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Aug 9 2020, 05:04 AM) *

In lesson 4 I learnt this
CODE
\w matches any alphanumeric character in upper or lower case and underscore
\W what isn't matched by the above


According to http://www.javascriptkit.com/javatutors/redev2.shtml :

CODE
\w matches any alphanumerical character (word characters) including underscore (short for [a-zA-Z0-9_]).
\W matches any non-word characters (short for  [^a-zA-Z0-9_]).

Just A-Z as usual, in other word.

QUOTE
Strange is that in NTB Help the description of \w and \W is something that I don't even understand but at first glance looks like something different.
CODE
\w   any word delimiter. Matches any of \t\s!"&()*+,-./:;<=>?@[\]^`{|}~  

That looks like any character you can use between words (such as tabs, spaces, commas etc).

QUOTE
CODE
\W   any nonword delimiter. Equivalent to [^\t\s!"&()*+,-./:;<=>?@[\]^`{|}~]

That looks like the negation of the above. But the description "any nonword delimiter" seems misleading, shouldn't it be spelled "any non word delimiter"? ("Nonword" could mean anything that's not a word. )
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 9 2020, 07:36 AM
Post #5


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,733
Joined: 9-August 06
Member No.: 6



QUOTE(Christian J @ Aug 9 2020, 02:14 PM) *

That looks like any character you can use between words (such as tabs, spaces, commas etc).

Yes, but in reality it matches any non alphanumeric character except new line, just as the description in the book, only it has \w and \W the other way around.

QUOTE
CODE
\W   any nonword delimiter. Equivalent to [^\t\s!"&()*+,-./:;<=>?@[\]^`{|}~]

That looks like the negation of the above. But the description "any nonword delimiter" seems misleading, shouldn't it be spelled "any non word delimiter"? ("Nonword" could mean anything that's not a word. )


Yes, that I understood, it's just a negation of the first. But I still don't see how the underscore fits in. The author is Swiss, that may explain possible English mistakes. tongue.gif

I finally got around to installing an updated version. Now it works as in the book. But I think there are lots of differences between flavours, even if hopefully not as stupid as this one. That old engine is probably more than 20 years old. One would hope they strive to make them more compatible.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Aug 9 2020, 12:08 PM
Post #6


.
********

Group: WDG Moderators
Posts: 9,661
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Aug 9 2020, 02:36 PM) *

But I still don't see how the underscore fits in.

Actually none of them contain underscores:

CODE
\w   any word delimiter. Matches any of \t\s!"&()*+,-./:;<=>?@[\]^`{|}~
\W   any nonword delimiter. Equivalent to [^\t\s!"&()*+,-./:;<=>?@[\]^`{|}~]

unsure.gif
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 9 2020, 12:20 PM
Post #7


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,733
Joined: 9-August 06
Member No.: 6



I meant in neither of them, the second is just a negation of the first as we said.

\t is a tab and \s is a whitespace character, so the underscore can't hide there either.

Here it was clearly expressed. Even if I don't understand WHY underscore is grouped together with letters and digits they at least let us know that it is.
CODE
\w    Most engines: "word character": ASCII letter, digit or underscore

https://www.rexegg.com/regex-quickstart.html

Maybe I just a have bad book.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 9 2020, 12:56 PM
Post #8


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,733
Joined: 9-August 06
Member No.: 6



QUOTE
Why is an underscore (_) not regarded as a non-word character?


QUOTE
Historical reasons, likely related to the fact, that C Identifiers can consist of letters, numbers and underscore only.


QUOTE
You can still use [\W_] to match all non-word and underscore chars.


https://stackoverflow.com/questions/4953390...-word-character

At last some logic. laugh.gif

And I dissed my book out of confusion. The first explanation of \w and \W that I quoted is from the book and it's clear. My editor's Help isn't. The new version of the Help file doesn't mention underscore either.

CODE
\w        any "word" character
\W        any "non-word" character


That you already know what a "word character" is in regexp is presumed... The Help is actually quite good otherwise, even if terse.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 9 2020, 01:17 PM
Post #9


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,733
Joined: 9-August 06
Member No.: 6



There's actually a whole extra help file for regexp with my editor... The explanation for \w and \W is the same as in the ordinary Help though, but otherwise it seems very detailed.

I happened to read this bit that was just below the bit about \w and \W. It's sort of put-offish.

CODE
For compatibility with Perl, \s did not used to match the VT character (code 11), which made it different from the the POSIX "space" class. However, Perl added VT at release 5.18, and PCRE followed suit at release 8.34. The default \s characters are now HT (9), LF (10), VT (11), FF (12), CR (13), and space (32), which are defined as white space in the "C" locale. This list may vary if locale-specific matching is taking place. For example, in some locales the "non-breaking space" character (\xA0) is recognized as white space, and in others the VT character is not.


God help us. wacko.gif

If locale doesn't have another meaning in this context than otherwise, I don't understand why that should matter one bit! ninja.gif

Talking about locale. One thing that annoys me no end is the decimal point. I have Windows in English but my locale is of course Sweden. I know I can choose what decimal point to use, but I want comma to be the default for obvious reasons. Now I use a book keeping program that has a very nice feature. It's American, so it want period as decimal point when I enter a sum. But it has the good taste to interpret the decimal point key on he number pad as a period, in spite of that my default setting is comma.

That would be a very good feature for any editor, to let the user choose what character the decimal point key on the number pad should produce. Notetab at least has the good taste to accept both comma and period in calculations and I can mix them freely, but when writing other scripts that of course doesn't work.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 10 2020, 11:13 AM
Post #10


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,733
Joined: 9-August 06
Member No.: 6



Here is something both good and bad. Many engines support POSIX character classes. They seem to sort of duplicate some of the the squiggly stuff, but are much more readable.

For example...
[:code:] any letter or digit (same as [a-zA-Z0-9])
[:alpha:] any letter (same as [a-zA-Z][/code]

Bad thing: JavaScript doesn't support POSIX. Good thing: I think PHP does. And so does my editor.

If everything looked like that, at least I would have a lot easier to learn this.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
spalisetty   Pattern not working   Aug 2 2020, 10:24 AM
pandy   What do you mean it goes to a different page as we...   Aug 2 2020, 11:25 AM
spalisetty   Hello, I have written the code to make sure that ...   Aug 2 2020, 12:28 PM
pandy   Oh, now I understand. Are you sure the regex is co...   Aug 2 2020, 01:30 PM
spalisetty   Oh, now I understand. Are you sure the rexex is c...   Aug 2 2020, 01:38 PM
Christian J   Seems the space is causing problems: .{5, 10} whil...   Aug 2 2020, 01:18 PM
spalisetty   Seems the space is causing problems: .{5, 10} whil...   Aug 2 2020, 01:38 PM
pandy   Seems the space is causing problems: Duh. Thou...   Aug 2 2020, 02:20 PM
Christian J   Are you good as this? No. :wacko: You mean ...   Aug 2 2020, 02:29 PM
pandy   Nothing specific, but more than ANSI anyway. Say I...   Aug 2 2020, 04:43 PM
Christian J   To me it seems Regex is a power tool for those usi...   Aug 2 2020, 05:47 PM
pandy   To me it seems Regex is a power tool for those us...   Aug 2 2020, 08:28 PM
pandy   Add o that there are oodles of flavours of regexp....   Aug 2 2020, 09:06 PM
pandy   Add to that there are oodles of flavours of regexp...   Aug 2 2020, 09:06 PM
pandy   From https://stackoverflow.com/questions/150033/.....   Aug 3 2020, 07:59 AM
Christian J   Get that into pattern! :D :D :D :wacko: ...   Aug 3 2020, 12:30 PM
pandy   Are you sure it doesn't rely on JavaScript? Wh...   Aug 3 2020, 03:36 PM
Christian J   Are you sure it doesn't rely on JavaScript? ...   Aug 3 2020, 04:25 PM
pandy   I know, but disabling JS probably just means scrip...   Aug 3 2020, 05:31 PM
pandy   And here I found one we can use if we want to be s...   Aug 3 2020, 08:39 PM
pandy   This actually made me find my regexp book and flic...   Aug 3 2020, 08:48 PM
Christian J   And here I found one we can use if we want to be ...   Aug 4 2020, 07:32 AM
pandy   I'm too fast. I'm on lesson 4 already. I w...   Aug 8 2020, 01:03 AM
Darin McGrew   I think that's the key for regular expression...   Aug 4 2020, 08:24 AM
pandy   Yeah, different flavours are a stumble stone for m...   Aug 4 2020, 10:39 AM
Christian J   You could always add to the library of PATTERN att...   Aug 4 2020, 11:03 AM
pandy   I don't think my attempts should be trusted. ...   Aug 4 2020, 01:47 PM
Christian J   Nothing to worry about, considering the constant p...   Aug 5 2020, 05:45 PM
pandy   You should write one. :rolleyes:   Aug 5 2020, 06:31 PM
pandy   Or we just leave it to Darin. :lol:   Aug 5 2020, 07:42 PM
Christian J   Out of how many lessons? :-p Here's a challen...   Aug 8 2020, 10:12 AM
pandy   10. But I expect the remaining chapters to take lo...   Aug 8 2020, 10:04 PM
Christian J   In lesson 4 I learnt this [code]\w matches a...   Aug 9 2020, 07:14 AM
pandy   That looks like any character you can use between...   Aug 9 2020, 07:36 AM
Christian J   But I still don't see how the underscore fits...   Aug 9 2020, 12:08 PM
pandy   I meant in neither of them, the second is just a n...   Aug 9 2020, 12:20 PM
pandy   https://stackoverflow.com/questions/4953390....   Aug 9 2020, 12:56 PM
pandy   There's actually a whole extra help file for r...   Aug 9 2020, 01:17 PM
pandy   Here is something both good and bad. Many engines ...   Aug 10 2020, 11:13 AM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 27th April 2024 - 06:07 AM