Hi,
I was looking for any validation code in javascript which
essentially does the same thing as html tidy. i.e. The user enters some
data in a form text area and I want to perform a client side data
validation to ensure that it is valid xhtml before I submit the form.
Any ideas?
Karl. 5 1511
Very simple to do really, just use a RegExp:
var isValid=/^<[\w-\s="\/]+\/*>$/; //then
if (isValid.test(Y OURSTRINGHERE)) or so, OR
you could check at http://www.javascriptkit.com/cutpastejava.shtml for
some premades ones.
Danny
On Tue, 12 Jul 2005 20:13:54 -0700, <ka********@yah oo.com> wrote: Hi, I was looking for any validation code in javascript which essentially does the same thing as html tidy. i.e. The user enters some data in a form text area and I want to perform a client side data validation to ensure that it is valid xhtml before I submit the form. Any ideas? Karl.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
<html>
<head>
<script>
function isValid(){
var isValid=/^<[\w-\s="\/]+\/*>$/;
if(isValid.test ("<b>Hello World</b>")){
alert("It is Valid");
}else{
alert("Invalid" );
}
}
</script>
</head>
<body onload='isValid ();'>
CCC
</body>
</html>
fails!! It should pass. I am not looking for a regular expression
solution I am looking for a solution which ensures that the tags are
valid XHTML tags i.e. <b>XXX</b> should pass but <ccc>Fail</ccc> should
fail. ka********@yaho o.com wrote: <html> <head> <script> function isValid(){ var isValid=/^<[\w-\s="\/]+\/*>$/; if(isValid.test ("<b>Hello World</b>")){ alert("It is Valid"); }else{ alert("Invalid" ); } } </script> </head>
<body onload='isValid ();'> CCC </body>
</html> fails!! It should pass. I am not looking for a regular expression solution I am looking for a solution which ensures that the tags are valid XHTML tags i.e. <b>XXX</b> should pass but <ccc>Fail</ccc> should fail.
The RegExp is flawed, but clearly it wouldn't do what you're after if
it weren't.
There're several ways to do what you're looking for.
One suggestion:
Create an object and populate it with all possible XHTML tags you want
to consider valid.
var validTag = {
a: 1,
b: 1,
i: 1,
link: 1,
script: 1
};
ad nauseum. I'm not familiar with XHTML or whether it supports
namespacing, but if so, you can do some parsing of the fragment to
obtain those namespaces and check accordingly.
Having done that, you can now easily use a RegExp to extract tagnames
from any HTML or XHTML fragment and quickly check whether each tagname
is also a member of your validTag object.
Does XHTML not allow for custom tags?
i.e. In both FF and IE, working in HTML (purely quirksy), I can create
a node by an arbitrary name (number, ticket, ccc, or whatever) and work
with it as with any other HTMLElement. It's incredibly useful. ka********@yaho o.com wrote: Hi, I was looking for any validation code in javascript which essentially does the same thing as html tidy. i.e. The user enters some data in a form text area and I want to perform a client side data validation to ensure that it is valid xhtml before I submit the form. Any ideas? Karl.
You would need to use a client side XML parser and use the XML schema
for XHTML Strict (1.0) to validate it. ka********@yaho o.com wrote: The user enters some data in a form text area and I want to perform a client side data validation to ensure that it is valid xhtml before I submit the form.
Then you need to use a validating XML parser to parse the data. MSXML
which comes with IE on Windows is a validating parser so it could help
you doing that, in theory at least. In reality the problem is that MSXML
is not going to load the DTD from w3.org if you script is loaded from
another server, unless you change the security settings.
It could work if you place the DTDs (or the DTD you want to validate
against) on your own server and then make sure that e.g. http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd in the DOCTYPE
declaration is replaced by the URL to the resource on your server but I
have never tried that.
And other browsers like Mozilla or Opera do not have a validating XML
parser so you are better off doing the validation on the server.
--
Martin Honnen http://JavaScript.FAQTs.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dfirefire |
last post by:
Hi, i tried to validate a html doc, but the validator complained without
reason. This is an excerpt of the validation results:
Below are the results of attempting to parse this document with an SGML
parser.
1.. Line 24, column 19: there is no attribute "SRC" (explain...).
<embed src="firesite/img/flashtest.swf" quality="high"
pluginspage="http
^2.. Line 24, column 56: there is no attribute
|
by: sinister |
last post by:
I wanted to spiff up my overly spartan homepage, and started using some CSS
templates I found on a couple of weblogs. It looks fine in my browser (IE
6.0), but it doesn't print right. I tested the blogs, and one definitely
didn't print right.
Surveying the web, my impression is that CSS is very unreliable, because
even updated browsers fail to implement the standards correctly.
So should one just avoid CSS? Or is it OK if used...
|
by: Pasta Bolognese |
last post by:
Open VS.2003.
Click on a control on an aspx page in the HTML view.
Does it tell me the pixel position on the page?
Nooooooooooo.................
|
by: Nick Gilbert |
last post by:
Hi
I have a number of pages where it is valid for the user to enter HTML.
On these pages, I have turned off RequestValidation ("ValidateRequest =
false" in the page directive) so that the HttpRequestValidationException
that gets thrown if HTML is included in the Form, doesn't get thrown.
This is fine.
However, on some of those pages, there are fields where I don't want
|
by: Alan Silver |
last post by:
Hello,
I am writing a web form where the user is allowed to enter HTML into one
of the textboxes. This of course generates the "potentially dangerous"
server error.
Now I know I can switch off the validation for the page by using the
validateRequest page directive, but this switches it off for *all*
controls on the page. I have loads and loads of them, but only want to
allow HTML in this one control. I really don't want to have to...
| |
by: Arthur Dent |
last post by:
Hello all, ive been programming with ASP.NET since it came out, but am just
getting my feet with now with v.2.
Ive noticed something strange in the way my HTML tables get rendered with 2.
I use tables to layout my pages, doing three rows, a header, content and
footer. When i do this, i make the tables height=100%,
so the footer always shows up at the very bottom of the page.
With 2.0/2005 though, when it renders the pages, it doesnt...
|
by: Nalaka |
last post by:
Hi,
I suddenly started getting a lot of errors from html validation (some CSS)
so I followed the following instructions to disable it.
If you'd rather not have these types of HTML validation errors show up in
your error-list, you can disable this functionality by selecting the
Tools->Options menu item in VS or Visual Web Developer. Select the
TextEditor->Html->Validation tree option in the left-hand side of the
|
by: VK |
last post by:
Hi,
After the response on my request from W3C I'm still unclear about Tidy
vs. Validator discrepansies. That started with <IFRAME> issue, but
there is more as I know. Anyway, this very basic HTML page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html401/strict.dtd">
<html>
<head>
|
by: Tatyana |
last post by:
Hi All,
I have a question regarding validation with XHTML on ASP.Net websites.
Our site is built on ASP.NET 2.0 with validation XHTML. Search Engine
Optimizer advised us that we should change it to HTML because it causes
problems.
We can switch it to HTML validation in production only:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
by: =?Utf-8?B?U2hhd24gUmFtaXJleg==?= |
last post by:
I am coming at the world from the standpoint of a veteran ASP Classic
developer. I am not clear on the advantages of using the ASP.NET control
over standard HTML control.
With the ASP.NET controls the rendered names are changed and I appear to be
limited in what javascript events I can fire. I also can not seem to figure
out how to setup a onsubmit() event.
With standard HTML I can setup any javascript event I want and the names...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |